Created
March 9, 2012 06:51
-
-
Save d33pfri3d/2005383 to your computer and use it in GitHub Desktop.
jQuery : Ajax Deferred
This file contains hidden or 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
$.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