Created
August 20, 2016 22:05
-
-
Save englishextra/79df33f0b9eb8828c12b2a760f74211c to your computer and use it in GitHub Desktop.
an async AJAX call without jQuery
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
/*! | |
* 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