Last active
December 16, 2019 20:54
-
-
Save TommyZG/37fc87d319fc397c4e5e969c124d5f72 to your computer and use it in GitHub Desktop.
Example of jQuery Promise/Deferred usage
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
$(document).ready(function() { | |
getSomething().done(function() { | |
$("#success-alert").show(); | |
}).fail(function() { | |
$("#fail-alert").show(); | |
}); | |
}); | |
function getSomething() { | |
var deferred = $.Deferred(); | |
$('#success').on('click', function() { | |
deferred.resolve(); | |
}); | |
$('#fail').on('click', function() { | |
deferred.reject(); | |
}); | |
return deferred.promise(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment