Perhaps not all of them. Microsoft recommends not to use
versions 4 and 5. They say, check for 6.0. If that is not there,
use 3.0.
I've found an article on MSDN stating exactly the same. Furthermore,
there's another article on MSDN that doesn't encourage using version
5, which is installed by Office 2003. Inspecting my computer which has
Office 2003, I've confirmed that msxml5.dll is located in:
"C:\Program files\Common files\Microsoft Shared\OFFICE11\MSXML5.DLL"
All earlier versions are for IE versions before 6.
Nowadays, it might be odd to find IE 5 or 5.5 on an XP or Vista
installation. But, in that case, I suppose IE 5 could instantiate
versions 3 and 6, because both XP and Vista come with the mentioned
versions of MSXML. But I can't test this supposition.
After searching my Windows Vista registry for "Msxml2.XMLHTTP", I've
found out two CLSID keys: one related to the "msxml2.dll" (version 2.6
on my system) and the other related to the "msxml3.dll" (version 3.0).
This is consistent with the MSDN article "MSXML 3.0 GUIDs and
ProgIDs" (
http://msdn.microsoft.com/en-us/library/ms766426(VS.
85%29.aspx).
But searching further, I've noticed that both "Microsoft.XMLHTTP" and
"Microsoft.XMLHTTP.1.0" are related to the msxml3.dll too. What? Now
it's not consistent with the same article on MSDN.
I've used VBA to instantiating "Msxml2.XMLHTTP", but I couldn't find
any property informing the dll filename or XMLHTTP version. I think
I'd need some C++ code to inspect what is really going on...
In short, after studying this matter I think the best approach would
be (referring to the OP's example):
var ajax = {
transport : (function () {
var req = null;
if (typeof window.XMLHttpRequest != "undefined") {
// IE7+, FF, Opera 8.0+, Safari.
try { req = new XMLHttpRequest(); }
catch (ex1) { } // Ignores.
} else if (typeof window.ActiveXObject != "undefined") {
//IE 5+, 6, or IE7/8 with native XMLHTTP support disabled.
try { req = new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (ex2) {
try { req = new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (ex3) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (ex4) { } // game over.
}
}
} else {
// alert("Your browser doesn't support AJAX. Sorry!");
}
return req;
})(),
// other properties.
};