Skip to content

Instantly share code, notes, and snippets.

@cemerson
Created February 18, 2014 11:30
Show Gist options
  • Save cemerson/9069250 to your computer and use it in GitHub Desktop.
Save cemerson/9069250 to your computer and use it in GitHub Desktop.
jQuery: Promise and Deferred with getJSON
//http://nurkiewicz.blogspot.com/2013/03/promises-and-deferred-objects-in-jquery.html
function doubleAjax() {
var deferred = $.Deferred();
$.getJSON('square/3', function(threeSquare) {
deferred.notify(threeSquare)
$.getJSON('square/4', function(fiveSquare) {
deferred.resolve(fiveSquare);
});
});
return deferred.promise();
}
doubleAjax().
progress(function(threeSquare) {
console.info("In the middle", threeSquare);
}).
done(function(fiveSquare) {
console.info("Done", fiveSquare);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment