Created
May 11, 2016 14:23
-
-
Save ondrek/e6ddc1280444d7661d3f93825c35306e to your computer and use it in GitHub Desktop.
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( 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