Skip to content

Instantly share code, notes, and snippets.

@lazuee
Forked from m5r/xhr.js
Created May 28, 2022 17:06
Show Gist options
  • Save lazuee/2462c7d461645dc0a5e2751c05312ff4 to your computer and use it in GitHub Desktop.
Save lazuee/2462c7d461645dc0a5e2751c05312ff4 to your computer and use it in GitHub Desktop.
ES6 XHR from Mackan from Devcord Discord
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