Skip to content

Instantly share code, notes, and snippets.

@yosmoc
Created November 23, 2009 03:33
Show Gist options
  • Select an option

  • Save yosmoc/240870 to your computer and use it in GitHub Desktop.

Select an option

Save yosmoc/240870 to your computer and use it in GitHub Desktop.
HTTP = {};
HTTP._factories = [
function() {return new XMLHttpRequest();},
function() {return new ActiveXObject("Msxml2.XMLHTTP");},
function() {return new ActiveXObject("Microsoft.XMLHTTP");}
];
HTTP._factory = null;
HTTP.newRequest = function() {
if (HTTP._factories != null) return HTTP._factory();
for (var i = 0; i < HTTP._factories.length; i++){
try {
var factory = HTTP._factories[i];
var request = factory();
if (request != null) {
HTTP._factory = factory;
return request;
}
} catch(e) {
continue;
}
}
HTTP._factory = function() {
throw new Error("XMLHttpRequest not supported");
}
HTTP._factory();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment