Skip to content

Instantly share code, notes, and snippets.

@gmatheu
Created January 23, 2015 20:46
Show Gist options
  • Save gmatheu/a293a2cfe0830c970ff8 to your computer and use it in GitHub Desktop.
Save gmatheu/a293a2cfe0830c970ff8 to your computer and use it in GitHub Desktop.
Ajax Request Promise
var deferred = $.Deferred();
var ajax = $.ajax({url: '/config'}).
done(function(data) {
console.log('Data: ' + data);
deferred.resolve(data);
}).
fail(function (xhr, status) {
console.log("Fail: " + xhr.status);
deferred.fail();
});
$.when(ajax).done(function(d) {
console.log('Arguments: ' + d);
console.log(arguments);
});
console.log('Deferred state: ' + deferred.state());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment