Skip to content

Instantly share code, notes, and snippets.

@fomigo
Forked from d33pfri3d/gist:2005383
Created March 10, 2012 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fomigo/2011903 to your computer and use it in GitHub Desktop.
Save fomigo/2011903 to your computer and use it in GitHub Desktop.
jQuery : Ajax Deferred
$.X = function(){
var deferred = new $.Deferred();
// DO AJAX
/*
$.ajax({
// Do Ajax Call
url: '',
//Success
success : deferred.resolve;
// Fail
error : deferred.reject;
})
return deferred.promise();
*/
return $.ajax({
// Do Ajax Call
url: ''
}).promise();
}
$('a').on('click', function(){
$.X().then(function( data ){
// Do something with data
});
});
/*
X.done(function(){
console.log('done');
});
X.fail(function(){
console.log('failed');
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment