Jquery - why does $ .ajax call a success handler when a request is interrupted because my server is down?

When I withdraw my server and make an ajax request, firebug shows that the request is interrupted a few seconds after the request, and my handler successreceives the call.

Why is the success handler called, should it not be an error handler? And how can I reliably detect that it was not really successful?

CODE:

            $.ajax({
                url: url,
                type: "POST",
                data: data,
                dataType: "json",
                success:function(data, statusText, xhr){
                  //gets called on success, or even when server is down.
                },
                error: function(){
                  //called if server returns error, but not if it doesn't respond
                }
            });

UPDATE: , . , , , , , . , - .

+5
2

, (?) 1.4.2 jQuery.

jQuery:

1.4.2 jquery ajax -/ , : trailing "|| xhr.status === 0" httpSuccess

, jQuery. , :

$.ajax({
   type: "POST",
   url: "http://madeUpServerthatdoesnotExist.com/index.php",
   data: "id=1",
   success: function(msg){
     if(this.xhr().status === 0 ){
           errorHandler();
     }
     else {
           alert('Success');
     }
   },
    error: errorHandler
 });

function errorHandler(){
            alert('Freakin error');
}

, , !

EDIT: , ​​jQuery, ,

+3
+2

All Articles