Created
April 19, 2012 18:26
-
-
Save benbishop/2422835 to your computer and use it in GitHub Desktop.
getXHR
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 getXHR(url, callback) { | |
var req = new XMLHttpRequest(); | |
req.onreadystatechange = function() { | |
if (this.readyState == 4) { | |
if (this.status == 200 || this.status == 0) { | |
callback(this.responseText); | |
} else { | |
alert('Request failed') | |
} | |
} | |
} | |
req.open("GET", url, true); | |
req.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment