Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// see this gist as well: https://gist.github.com/sergio-fry/3917217
// create the "promises" objects (deferred objects)
var address = $.ajax({});
var tweets = $.ajax({});
var facebook = $.ajax({});
// wait for all to be done
$.when(address, tweets, facebook).then(function (addressResult, tweetsResult, facebookResult) {
/* all solved and the result is on each function argument */
});
// wait for one to be done
$.when(address).then(function (addressResult) {
/* address promise is solved and the result is on the function argument */
});
// when / then / done / fail ?? Here:
//
// https://stackoverflow.com/questions/5436327/jquery-deferreds-and-promises-then-vs-done
//
// The callbacks attached to done() will be fired when the deferred is resolved.
// The callbacks attached to fail() will be fired when the deferred is rejected.
//
// Prior to jQuery 1.8, then() was just syntactic sugar:
promise.then(doneCallback, failCallback);
// was equivalent to
promise.done(doneCallback).fail(failCallback);
// As of 1.8, then() is an alias for pipe() and returns a new promise
// see this for pipe: https://stackoverflow.com/questions/9583783/when-should-i-use-jquery-deferreds-then-method-and-when-should-i-use-the-pip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.