-
-
Save lazuee/2462c7d461645dc0a5e2751c05312ff4 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