JQuery Form Plugin - Does Not Call Error Callback on Internal Server Error (500)

I have a server returning a 500 status code, and my jQuery Form calls a success callback instead of an error callback.

jQuery version: 1.7.1
jQuery version: 2.73 march 2011
apache2 server

Here are some code snippets:

var options =
{
       error         : on_upload_error
    ,  success       : on_upload_succes
};

// bind form using 'ajaxForm'
$( '#upload-form' ).ajaxForm( options );



function on_upload_error( jqXHR, textStatus, errorThrown )
{
    console.log( "in error function" );
}




function on_upload_succes( responseText, statusText, xhr, form )
{
    console.log( 'responsText: ' + responseText );
    console.log( 'statusText: ' + statusText );
    console.log( xhr );
    console.log( form );

    // ....
}

The server headers seem right to me:

HTTP/1.1 500 Internal Server Error
Date: Wed, 09 May 2012 18:35:11 GMT
Server: Apache/2.2.16 (Debian)
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 405
Connection: close
Content-Type: text/html; charset=iso-8859-1

I can not get this to show "in error function". In addition, the statusText parameter returned by on_upload_success contains the string "success".

All hints are welcome.

+3
source share
2 answers

You can use alert(xhr.responseText);to see the related error message.

0

, 500 - HTTP, , - - , .

, jquery 500 ,

$.ajax({
    statusCode: {
        500: function() {
          alert("Something went wrong !");
        }
      }
   });

, jquery api: https://api.jquery.com/jQuery.ajax/

500 : 500 JSON (jQuery)

: jquery ajax 500

0

All Articles