Created
February 18, 2014 11:30
-
-
Save cemerson/9069250 to your computer and use it in GitHub Desktop.
jQuery: Promise and Deferred with getJSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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