Created
December 16, 2014 09:06
-
-
Save terrymun/1405cfccbec07c77fd85 to your computer and use it in GitHub Desktop.
Better $.ajax() requests — chaining and compunding
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 a1 = $.ajax({ | |
url: '/path/to/file', | |
dataType: 'json' | |
}), | |
a2 = a1.then(function(data) { | |
// .then() returns a new promise | |
return $.ajax({ | |
url: '/path/to/another/file', | |
dataType: 'json', | |
data: data.sessionID | |
}); | |
}); | |
a2.done(function(data) { | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment