Created
July 18, 2013 19:05
-
-
Save juandopazo/6032051 to your computer and use it in GitHub Desktop.
DOM Promises are read only
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 ajax(url) { | |
return new Promise(function (resolver) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
resolver.resolve(xhr.responseText); | |
} else { | |
resolver.reject(new Error('There was a problem with the request.')); | |
} | |
} | |
}; | |
xhr.open('GET', url); | |
xhr.send(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment