Skip to content

Instantly share code, notes, and snippets.

@CarlRevell
Created July 25, 2016 09:03
Show Gist options
  • Save CarlRevell/26abb506e93a66b71b067416f3b04f66 to your computer and use it in GitHub Desktop.
Save CarlRevell/26abb506e93a66b71b067416f3b04f66 to your computer and use it in GitHub Desktop.
function getData(method, url) {
return new Promise(function(resolve, reject){
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function() {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status;
statusText: xhr.statusText
});
}
};
xhr.onerror = function() {
reject({
status: this.status;
statusText: xhr.statusText
});
};
xhr.send();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment