Created
October 28, 2016 20:29
-
-
Save m5r/59a3e632c920ba3a1ba666d19eb68613 to your computer and use it in GitHub Desktop.
ES6 XHR from Mackan from Devcord Discord
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 loadData(url){ | |
return new Promise((resolve, reject) => { | |
let xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function(){ | |
if(xmlhttp.readyState === XMLHttpRequest.DONE){ | |
if(xmlhttp.status === 200){ | |
resolve(xmlhttp.responseText); | |
}else{ | |
reject(xmlhttp.status); | |
} | |
} | |
}; | |
xmlhttp.open("GET", url, true); | |
xmlhttp.send(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment