This article illustrates the way Ajax gets XMLHTTP objects. Share to everyone for your reference, specific as follows:
Ajax to use the XMLHTTP object, I have seen a variety of access to the object's writing, feel that the most elegant writing. First, consider the appropriate browser, second, consider the priority load order, from the high version to the lower version of the temptation, and finally if not found, throw an exception.
function Factoryxmlhttprequest () {
if (window). XMLHttpRequest) {return
new XMLHttpRequest ();
} else if (window. ActiveXObject) {
var msxmls = new Array (
' msxml2.xmlhttp.5.0 ',
' msxml2.xmlhttp.4.0 ',
' msxml2.xmlhttp.3.0 ',
' msxml2.xmlhttp ', '
microsoft.xmlhttp ');
for (var i = 0; i < msxmls.length; i++) {
try {return
new ActiveXObject (Msxmls[i]);
catch (e) {
}
}
throw new Error ("Could not instantiate XMLHttpRequest");
}
I hope this article will help you with Ajax programming.