-
-
Save ehimsi/bed442607fa4e393b59073935b32956f to your computer and use it in GitHub Desktop.
simple jQuery Deferred example
This file contains 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
function getData() { | |
var deferred = $.Deferred(); | |
$.ajax({ | |
'url': 'http://google.com', | |
'success': function(data) { | |
deferred.resolve('yay'); | |
}, | |
'error': function(error) { | |
deferred.reject('boo'); | |
} | |
}); | |
return deferred.promise(); | |
} | |
$.when(getData()).done(function(value) { | |
alert(value); | |
}); | |
getData().then(function(value) { | |
alert(value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment