Reputation: 27027
I do a JQuery Ajax call with the "error" option set. In my "error" method I would like to handle an HTTP 408 differently from a normal HTTP 500.
The problem is that the jxhr.statusCode is 0 and the "status" value is simply "error"! But in firebug I can see that the service definitely returned status code 408.
Why would the jxhr.statusCode be 0? Is there another way to identify an HTTP 408 error?
My error handler code looks as follows (for a 408 error the code just continues into the 'else' block):
error: function (jxhr, status, error) {
var $message = element.next().find('.loadmask-msg-label');
if (jxhr.status == 401)
$message.html(settings.unauthorizedMessage);
else if (jxhr.status == 408)
$message.html(settings.timeoutMessage);
else
$message.html(settings.errorMessage);
Upvotes: 4
Views: 2792
Reputation: 27027
The problem was FIREFOX. In any browser except Firefox the status code is 408. In Firefox the status code is 0, and no response headers are returned. Also, Firefox seems to re-request 10 times because of the 408 response, I have no idea why! And this is only for an HTTP 408 response.
In the end we had to return a HTTP 500 error with custom headers.
Dirty :(
Upvotes: 3
Reputation: 148524
According to Jquery you should do this :
$.ajax({
statusCode: {
404: function() {
alert('page not found');
}
}
})
;
Upvotes: 3