Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// see this gist as well:
// 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:
// 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
// As of 1.8, then() is an alias for pipe() and returns a new promise
// see this for pipe:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment