Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active December 16, 2015 17:49
Show Gist options
  • Save simonewebdesign/5473323 to your computer and use it in GitHub Desktop.
Save simonewebdesign/5473323 to your computer and use it in GitHub Desktop.
XMLHttpRequest - the standard way
// Full docs: https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest
var xhr,
url = "menu.html",
method = "GET";
if (XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xhr = new XMLHttpRequest();
} else {
// code for IE5, IE6
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
// xhr.responseText contains the response
}
}
xhr.open(method, url);
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment