For $.ajax()
and family .success
is merely a synonym for Deferred's .done
, and likewise .error
is a synonym for .fail
.
So in fact the examples you show are already deferred methods, but with different names.
.complete
is mostly a synonym for the new jQuery 1.6 .always
, and you can get the same effect using $.then(cb, cb)
, which will cause cb
to be invoked whether the AJAX call succeeds or not. I believe there are minor differences in which parameters are passed to the "fail" callbacks between the .complete
, .always
and $.then
variants.
I personally prefer to use the Deferred version of those named functions, because then you don't need to worry about whether your deferred objects are jqXHRs or not. Only jqXHRs
have .success
, .error
, and .complete
, but every Deferred (including jqXHRs) has .done
, .fail
and .always
.
EDIT it seems the jQuery devs agree with me - they've announced that .success
, .error
and .complete
will be deprecated in jQuery 1.8