3

I have a server returning Status code 500 and my jQuery Form calls the success callback instead of the error callback.

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

These 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 headers from the server seem correct 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't get this to show "in error function". On top of that, the statusText parameter returned to on_upload_success contains a string "success".

All clues welcome

Popo
  • 2,402
  • 5
  • 33
  • 55

2 Answers2

0

You should use alert(xhr.responseText); to see the error message associated.

HackerKarma
  • 620
  • 7
  • 18
0

First of all , The 500 Internal Server Error is a very general HTTP status code that means something has gone wrong on the web site's server but the server could not be more specific on what the exact problem is.

It is know for jquery not to call error function upon occurance of 500 internal error , so the usual way of handling this is using status code

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

for more info about using status code , review jquery api: https://api.jquery.com/jQuery.ajax/

more info about failure to handle 500 error: Handle 500 errors in JSON (jQuery)

also check this out : jquery ajax ignores 500 status error

Community
  • 1
  • 1
ProllyGeek
  • 15,517
  • 9
  • 53
  • 72