Skip to content

Instantly share code, notes, and snippets.

@terrymun
Created December 16, 2014 09:06
Show Gist options
  • Save terrymun/1405cfccbec07c77fd85 to your computer and use it in GitHub Desktop.
Save terrymun/1405cfccbec07c77fd85 to your computer and use it in GitHub Desktop.
Better $.ajax() requests — chaining and compunding
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