Mozilla was creating a JavaScript object called XMLHttpRequestthat behaves exactly the same as Microsoft’s version. Both Safari (as of 1.2) and Opera (as of 7.6) copied Mozilla’s implementation, creating their own XMLHttpRequestobjects.
To allow creation of an XML HTTP request in a common way, just add this simple wrapper class to your pages:
if (typeof XMLHttpRequest == “undefined” && window.ActiveXObject) {
function XMLHttpRequest() {
var arrSignatures = [“MSXML2.XMLHTTP.5.0”, “MSXML2.XMLHTTP.4.0”,
“MSXML2.XMLHTTP.3.0”, “MSXML2.XMLHTTP”,
“Microsoft.XMLHTTP”];
for (var i=0; i < arrSignatures.length; i++) {
try {
var oRequest = new ActiveXObject(arrSignatures[i]);
return oRequest;
} catch (oError) {
//ignore
}
}
throw new Error(“MSXML is not installed on your system.”);
}
}
This code allows you to use the following line to create an XML HTTP request in all browsers that support it:
var oRequest = new XMLHttpRequest();
After this point, the XML HTTP request can be used in all supporting browsers as described in the previous sections.