Skip to content

Instantly share code, notes, and snippets.

@englishextra
Created August 20, 2016 22:05
Show Gist options
  • Save englishextra/79df33f0b9eb8828c12b2a760f74211c to your computer and use it in GitHub Desktop.
Save englishextra/79df33f0b9eb8828c12b2a760f74211c to your computer and use it in GitHub Desktop.
an async AJAX call without jQuery
/*!
* an async AJAX call without jQuery
* stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery
* gist.github.com/englishextra/79df33f0b9eb8828c12b2a760f74211c
*/
function doAsyncAjax(url, callback) {
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
callback(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment