Cleaning up the factory
Category None
After some more research and Johan's link, some interesting tidbits about MSXML2 including its sordid history became more apparent. So I've cut the factory down to size:
function initXMLHttpRequest(){
var objHTTP = null;
if (window.XMLHttpRequest) { //IE7 with native XMLHTTP and FF
try{
objHTTP = new XMLHttpRequest();
}catch(e){}
}else if(window.ActiveXObject){ //IE7 without native XMLHTTP, IE6 and below
if(g_XMLHttpRequest_ActiveX){
objHTTP = new ActiveXObject(g_XMLHttpRequest_ActiveX);
}else{
var xmlhttp = new Array(
'Msxml2.XMLHTTP.7.0',
'Msxml2.XMLHTTP.6.0',
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP');
for(var i = 0; i < xmlhttp.length; i++){
try{
objHTTP = new ActiveXObject(xmlhttp[i]);
if(objHTTP != null){
g_XMLHttpRequest_ActiveX = xmlhttp[i];
break;
}
}catch(e){}
}
}
}
return objHTTP;
}
So why the cutbacks? Based on the XML Team's blog entry, here's why:
Good catch and thanks to the XML team for posting the details and history of this bad boy.
By the way, if you read the first post, you might catch that I made a clarification in the comment "//IE7 with native XMLHTTP and FF". This is because as I mentioned in IE7 there is native support for the XHR object and no need to invoke the ActiveX stuff - but only if it's turned on (which it is by default). But if you notice a browser using ActiveX, here's the setting:
Happy Ajax-ing...
After some more research and Johan's link, some interesting tidbits about MSXML2 including its sordid history became more apparent. So I've cut the factory down to size:
function initXMLHttpRequest(){
var objHTTP = null;
if (window.XMLHttpRequest) { //IE7 with native XMLHTTP and FF
try{
objHTTP = new XMLHttpRequest();
}catch(e){}
}else if(window.ActiveXObject){ //IE7 without native XMLHTTP, IE6 and below
if(g_XMLHttpRequest_ActiveX){
objHTTP = new ActiveXObject(g_XMLHttpRequest_ActiveX);
}else{
var xmlhttp = new Array(
'Msxml2.XMLHTTP.6.0',
'MSXML2.XMLHTTP.3.0',
for(var i = 0; i < xmlhttp.length; i++){
try{
objHTTP = new ActiveXObject(xmlhttp[i]);
if(objHTTP != null){
g_XMLHttpRequest_ActiveX = xmlhttp[i];
break;
}
}catch(e){}
}
}
}
return objHTTP;
}
So why the cutbacks? Based on the XML Team's blog entry, here's why:
| Msxml2.XMLHTTP.7.0 | Doesn't exist - we put it there for future protection but 6 is the highest we'll see for a while. It's shipping in Vista. |
| Msxml2.XMLHTTP.5.0 | Was specifically for Microsoft Office applications. Irrelevant to web applications. |
| Msxml2.XMLHTTP.4.0 | No maintenance work on this version, 3.0 is the default fallback. |
| Msxml2.XMLHTTP | This gives the same result as 3.0 - it is the default. No need for this one. |
| Microsoft.XMLHTTP | Not recommended, an old namespace. |
Good catch and thanks to the XML team for posting the details and history of this bad boy.
By the way, if you read the first post, you might catch that I made a clarification in the comment "//IE7 with native XMLHTTP and FF". This is because as I mentioned in IE7 there is native support for the XHR object and no need to invoke the ActiveX stuff - but only if it's turned on (which it is by default). But if you notice a browser using ActiveX, here's the setting:
Happy Ajax-ing...
