Skip to content

Instantly share code, notes, and snippets.

@maxdignan
Created July 18, 2015 17:08
Show Gist options
  • Save maxdignan/f2e5132e5070f39fcd80 to your computer and use it in GitHub Desktop.
Save maxdignan/f2e5132e5070f39fcd80 to your computer and use it in GitHub Desktop.
Vanilla JS HTTP GET Request
function httpGet(theUrl, callback, callbackContext, errorCallback) {
var req = new XMLHttpRequest();
req.open("GET", theUrl, true);
req.onreadystatechange = (function(){
if (req.readyState == 4 && (req.status >= 200 && req.status < 300)){
callback.call(callbackContext);
} else if (req.readyState == 4) {
errorCallback();
}
});
req.send();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment