Created
July 25, 2016 09:03
-
-
Save CarlRevell/26abb506e93a66b71b067416f3b04f66 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(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