Skip to content

Instantly share code, notes, and snippets.

@benbishop
Created April 19, 2012 18:26
Show Gist options
  • Save benbishop/2422835 to your computer and use it in GitHub Desktop.
Save benbishop/2422835 to your computer and use it in GitHub Desktop.
getXHR
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