Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Created April 1, 2016 20:08
Show Gist options
  • Save pzp1997/373c8573b5978ab82e8dc247632433f1 to your computer and use it in GitHub Desktop.
Save pzp1997/373c8573b5978ab82e8dc247632433f1 to your computer and use it in GitHub Desktop.
Uses XMLHttpRequest to make an AJAX get request.
var getRequest = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE)
callback(xhr.status === 200 ? xhr.responseText : null);
};
xhr.open('GET', url, true);
xhr.send();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment