Last active
January 15, 2016 15:13
-
-
Save socketwiz/24fac594ba7d69f58289 to your computer and use it in GitHub Desktop.
ajax promises
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
var $promise = $.ajax(options); | |
$promise | |
.then(function(data){ | |
// data will be from the ajax call | |
return data; | |
}) | |
.then(function(data){ | |
// data will be the data you return from the previous call | |
return 'foo'; | |
}) // as needed | |
.done(function(data){ | |
// data will be the string foo | |
return $.ajax(options); | |
}) | |
.done(function(promise)){ | |
// the promise from the previous ajax call | |
promise.then(function(){}) | |
.done(function(){}) | |
.fail(function(){}); | |
}) | |
.fail(function(error){}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment