Skip to content

Instantly share code, notes, and snippets.

@socketwiz
Last active January 15, 2016 15:13
Show Gist options
  • Save socketwiz/24fac594ba7d69f58289 to your computer and use it in GitHub Desktop.
Save socketwiz/24fac594ba7d69f58289 to your computer and use it in GitHub Desktop.
ajax promises
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