I have a very simple ajax request:
$.get(url, data)
.done(function () { })
.fail(function () { })
If there is an error at url, it will return a status code like “500,” for instance. Apparently, jQuery considers its promise on the jqxhr object at this point since it will execute .done rather than .fail. My question is twofold:
By default, when is .fail triggered with respect to ajax and is there any way to change this default?
Secondly, the only way to have special handling for a bad request seems to be something like:
.done(function (msg, tm, jqxhr) {
if (jqxhr.status < 200 || jqxhr.status >= 300) performFailure();
});
Is there a better way to find and handle responses that would be considered “bad?”
After looking into this further, it seems that jQuery does in fact use
.fail()correctly. The problem was that my server was emitting 200 for certain errors. In other words, this is not a jQuery issue to begin with.