Skip to content

Instantly share code, notes, and snippets.

@Chalarangelo
Created July 15, 2017 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chalarangelo/808c5d0558ce79d6c813819ce8998356 to your computer and use it in GitHub Desktop.
Save Chalarangelo/808c5d0558ce79d6c813819ce8998356 to your computer and use it in GitHub Desktop.
AJAX GET request function
// Send a 'GET' request to the specified url and run the callback function when it completes.
function httpGetAsync(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
};
xmlHttp.open('GET', url, true);
xmlHttp.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment