Skip to content

Instantly share code, notes, and snippets.

@maartenJacobs
Created June 8, 2011 12:57
Show Gist options
  • Save maartenJacobs/1014367 to your computer and use it in GitHub Desktop.
Save maartenJacobs/1014367 to your computer and use it in GitHub Desktop.
HTTPObject (Bulletproof) in a configobject
// As seen in Bulletproof Ajax (The warrior, not the faulty abbreviation), by Jeremy Keith
var httpObject = function(){
if(window.XMLHttpRequest){
httpObject = function(){
return new XMLHttpRequest();
};
} else if(window.ActiveXObject) {
var xhr;
try{
xhr = new ActiveXObject("Msxml2.XMLHTTP");
httpObject = function(){
return new ActiveXObject("Msxml2.XMLHTTP");
};
} catch(e) {
// Disregard error, acquire HTTPObject
try{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
httpObject = function(){
return new ActiveXObject("Microsoft.XMLHTTP");
};
} catch(e) {
httpObject = function(){
// I give up.
return false;
};
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment