"ajax" jQuery call runs the success function, even if the server is not responding

The jQuery function seems to .ajaxrun the function 'success', even if it does not receive a response from the server. I consider this a mistake. I detected this event by checking if there are 'request.status===0', are there any other instances that I have to check where the function 'success'will run, even if there is an error?

I published the code that I am using below. How is this type of situation usually handled?

$.ajax({ 
    async : true, cache : false, dataType : 'json',
    type : 'POST',
    url : 'person/' + personKey,
    data : JSON.stringify({firstName:'Jilopi',}),

    success : function(data, textStatus, request){
        if( request.status === 0 ){
            alert('Error: problem saving person - no response');
        }else{
            alert('Success: saved person');
        }
    },
    error : function(request, textStatus, errorThrown){
        alert('Error: problem saving person');
    },
});
+3
source share
2 answers

" ", . : Opera ( , 304 0), 1.4.2 ( ) : http://github.com/jquery/jquery/blob/1.4.2/src/ajax.js#L551

jQuery 1.4.3 - , , .

: jQuery 1.4.3+, , status === 0.

+8

, ES- ! :

, ! ES REST API , ES Server!

!

ES !

- ES-!

http://your-server-url:9200/_cluster/health

jQuery :

(function poll(){
health_url = "http://your-server-url:9200/_cluster/health";
online_ajax = false;
setTimeout(function(){
    $.ajax({
     url: health_url,
     dataType: "json",
     success: function(data){
            if (data.status == 'yellow') {
                // Show Server-Online Status Message in your App
            } else {
                // Show Server-Offline Status Message in your App
            };
            //Setup the next poll recursively
            poll();
          }
      })
      .fail(function(){
            // Show Server-Offline Status Message in your App
      });
}, online_status_time_out);
})();

, !

!!!

0

Source: https://habr.com/ru/post/1770332/


All Articles