Skip to content

Instantly share code, notes, and snippets.

@Denny966
Forked from pbojinov/jquery.deferred.promise.js
Last active May 27, 2019 15:02
Show Gist options
  • Save Denny966/79a831cd0dc307ac6f872bb8f22355a4 to your computer and use it in GitHub Desktop.
Save Denny966/79a831cd0dc307ac6f872bb8f22355a4 to your computer and use it in GitHub Desktop.
simple jQuery Deferred example
function getData() {
const deferred = $.Deferred();
API.ajax({
url: [URL],
type: "GET",
dataType: "json",
headers: {
'Accept-Language': uiCulture
}
}).done((data: any) => {
deferred.resolve(data);
}).fail((data: any) => {
deferred.reject(data);
});
return deferred.promise();
}
getData().done(function(value) {
alert(value);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment