Skip to content

Instantly share code, notes, and snippets.

@tkheyfets
Created March 18, 2016 22:37
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 tkheyfets/87a82c89507a1308d784 to your computer and use it in GitHub Desktop.
Save tkheyfets/87a82c89507a1308d784 to your computer and use it in GitHub Desktop.
function get(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) {
resolve(xhr.response);
} else {
reject(Error(xhr.statusText));
}
};
xhr.onerror = function() {
reject(Error('Something not expected happened. Please check network connection'));
};
xhr.send();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment