Skip to content

Instantly share code, notes, and snippets.

@aaani
Created August 16, 2014 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaani/6ae030391ec3c668d01f to your computer and use it in GitHub Desktop.
Save aaani/6ae030391ec3c668d01f to your computer and use it in GitHub Desktop.
Pure javascript module to send an ajax get request. It works well on IE8+ and other modern browsers.
var GetXHR = (function() {
var module = {};
module.sendRequest = function(url, callback) {
var req;
if (window.XDomainRequest) {
req = new XDomainRequest();
if (!req) return;
req.onload = function(){
callback(JSON.parse(req.responseText));
}
req.open("get", url);
req.send();
} else {
req = new XMLHttpRequest();
if (!req) return;
req.onload = function(){
callback(JSON.parse(req.response));
}
req.open("get", url, true);
req.send();
}
}
return module;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment