If I handle jQuery AJAX errors using fail()
, I can use textStatus
to provide a nice error message to the user:
$.get("/some_script.php")
.done(function()
{
// It works!
})
.fail(function(jqXHR, textStatus, errorThrown)
{
switch(textStatus)
{
case 'timeout' :
alert("Timeout");
break;
case 'parsererror':
alert("Corrupted data")
break;
case 'error':
case 'abort':
default:
alert("Unknown error");
break;
}
});
But when I use the ajaxError()
global error handler, textStatus
is not available:
$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError)
{
...
});
I checked the event
, jqXHR
and ajaxSettings
objects to see if textStatus
is hiding inside them, but had no luck. thrownError
doesn't help me also.
All I want is to make ajaxError()
tell me what kind of error occurred: timeout, parsererror, error or abort, just like fail()
does.
How can I do that? Thanks.