Created
May 23, 2017 03:34
-
-
Save giancorzo/f0e06163129c380f9f149a5322bcfb16 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
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