Created
March 18, 2016 22:37
-
-
Save tkheyfets/87a82c89507a1308d784 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 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