I'm using jQuery.Deferred and registering the done
, fail
and then
handlers:
$.when( some_ajax(url) )
.done(function(result){})
.fail(function(){})
.then(function(){}); //just like that, with a single parameter
I've found that when my ajax call succeeds, done
and then
callbacks are called, in this order. However when the ajax fails, the fail
callback is called but I don't get to the then
callback.
I've read the jQuery.Deferred documentation but couldn't find a hint regarding the reason for this behavior.
When using always
instead of then
, it is called in both cases - success and failure (first done
/fail
is called, then always
is called). The documentation doesn't seem to indicate an expected difference between always
and then
in my described scenario, why do they behave differently?