Skip to content

Instantly share code, notes, and snippets.

@FerraBraiZ
Last active April 27, 2021 12:32
Show Gist options
  • Save FerraBraiZ/975f923afa20d7e6dfe434d7f4b9d1ba to your computer and use it in GitHub Desktop.
Save FerraBraiZ/975f923afa20d7e6dfe434d7f4b9d1ba to your computer and use it in GitHub Desktop.
jQuery $.ajax promise, $.when then()
let promisedData = function() {
let deferredQuery = $.Deferred();
$.ajax({
type: "GET",
crossDomain: true,
dataType: "json",
cache: false,
data: "data=data",
url: Url,
success: function( result )
{
deferredQuery.resolve( result );
},
error:function( result )
{
deferredQuery.reject( result );
}
});
return deferredQuery.promise();
};
$.when( promisedData() ).then(
function resolved( resolved ) {
console.log( 'Resolved: ', resolved );
},
function rejected( rejected ) {
console.log( 'Rejected: ', rejected );
}
).catch(
function error( error ) {
console.log( 'Error: ', error );
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment