Skip to content

Instantly share code, notes, and snippets.

@ondrek
Created May 11, 2016 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ondrek/e6ddc1280444d7661d3f93825c35306e to your computer and use it in GitHub Desktop.
Save ondrek/e6ddc1280444d7661d3f93825c35306e to your computer and use it in GitHub Desktop.
function getData( val ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
$.ajax('/foo/', {
data: { value: val },
dataType: 'json',
success: function( resp ){
}
})
);
}
getData('foo').then(function(resp){
// do something with the response, which may
// or may not have been retreived using an
// XHR request.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment