I ran into the code block below...and I don't understand it. I understand promises perfectly in the sense of (and everything that goes with it):
deferred.then(successCb, errorCb);
However, the code below seems to have three callbacks(complete
, fail
, done
) and I don't know where to begin looking - I can only guess an observable-like success
, failure
, finally
pattern, but that doesn't seem to be the case.
I checked random questions like jQuery deferreds and promises - .then() vs .done() and some docs like here. The docs seem to imply that complete
isn't even a thing and there are only always
(runs whether promise succeeds or fails, on resolve), done
('this will run if the $.get succeeds' - weird name for it), fail
(fail) conditions.
var promise = $.ajax({
type: 'POST',
url: 'www.foo.com',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: muhData
});
promise.complete(function(d) {
console.debug("complete");
}).fail(function(){
console.error("failed!");
}).done(function(d){
console.log('Done');
});
tl;dr: Wut code do?