Skip to content

Instantly share code, notes, and snippets.

@rayhon1014
Created April 10, 2017 22:06
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 rayhon1014/934536f59f5340a663950c5bb57cae2f to your computer and use it in GitHub Desktop.
Save rayhon1014/934536f59f5340a663950c5bb57cae2f to your computer and use it in GitHub Desktop.
// Wrap the $.getJSON() call to return a real Promise
// properly handling rejection with the available `.fail` method
var fetchJSON = function(url) {
return new Promise((resolve, reject) => {
$.getJSON(url)
.done((json) => resolve(json))
.fail((xhr, status, err) => reject(status + err.message));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment