Reputation: 13544
I'm trying to identify an error during submitting Ajax request via jQuery when the connection to the server is failed. I load the page from the server, then disconnect the network connection. The following error handle in the Ajax jquery is used:
error: function(xhr, status, error){
var errorMessage = xhr.status + ': ' + xhr.statusText
alert('Error - ' + errorMessage);
alert('Connection Error\nCould not connect to the server.');
$("#loading").removeClass("show");
$("#submit_btn").removeAttr("disabled");
}
The first alert prints out:
Error - 0: error
I could not able to evaluate the returned errors values to identify the error cause is due to connection failure or something else!
Upvotes: 1
Views: 227
Reputation: 14423
The docs say that an error code of 0
basically means the request could not be completed, while other errors could be due to request completing but some other error in the endpoint or with response.
So usually with the error code 0
you can assume that there was a network issue.
Upvotes: 1