Skip to content

Instantly share code, notes, and snippets.

@giancorzo
Created May 23, 2017 03:34
Show Gist options
  • Save giancorzo/f0e06163129c380f9f149a5322bcfb16 to your computer and use it in GitHub Desktop.
Save giancorzo/f0e06163129c380f9f149a5322bcfb16 to your computer and use it in GitHub Desktop.
const get = url => {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', _ => {
if (xhr.status !== 200) {
reject(new Error(xhr.statusText));
}
resolve(xhr.response);
});
xhr.open('GET', url);
xhr.send();
}
}
get('story.json').then(response => {
console.log("Success!", response);
}).catch(error => {
console.error("Failed!", error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment