Getting XMLHttpRequest Object
The following code (three different JavaScript segments) get the XMLHttpRequest object on the mapquest.com page.
This code is the ‘release’ version you see on the source behind the page. The variables have been obfuscated here (for example, _40, _99, etc. as variable names). However, formatting the JavaScript code (as done below) makes it easy to understand how the XMLHttpRequest object is created.
Code Listing 1. Getting the XMLHttpRequest Object from mapquest.com
if(_40.rpcType==dwr.engine.XMLHttpRequest)
{
if(window.XMLHttpRequest)
{
_40.req=new XMLHttpRequest();
}
else
{
if(window.ActiveXObject&&
!(navigator.userAgent.indexOf("Mac")>=0&&
navigator.userAgent.indexOf("MSIE")>=0))
{
_40.req=dwr.engine._newActiveXObject(dwr.engine._XMLHTTP);
}
}
}
dwr.engine._XMLHTTP=["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
dwr.engine._newActiveXObject=function(_99)
{
var _9a;
for(var i=0;i<_99.length;i++)
{
try
{
_9a=new ActiveXObject(_99[i]);
break;
}
catch(ex)
{
}
}
return _9a;
};
XMLHttpRequest Code Analysis from mapquest.com
The following figure shows various sections of the function that creates the XMLHttpRequest object for a given web browser on mapquest.com.
Figure 1. Analysis of Creating XMLHttpRequest Object on mapquest.com

Get the XMLHttpRequest on newer browsers
This code tries first to get the XMLHttpRequest object that is available on all the newer browsers (Internet Explorer 7, FireFox, Safari, and Opera).
if(window.XMLHttpRequest)
{
_40.req=new XMLHttpRequest();
}
Get the XMLHttpRequest on older Microsoft browsers
If the current browser is older versions of Internet Explorer, the following code gets executed. This code has a clever way of using an array (_XMLHTTP) to store various names of the XMLHTTP object used on the older IE versions. In newer browsers you can instantiate XMLHttpRequest() object; however in the older IE browsers, you would need to instantiate an ActiveXObject and pass it an XMLHTTP string.
if(window.ActiveXObject&&
!(navigator.userAgent.indexOf("Mac")>=0&&
navigator.userAgent.indexOf("MSIE")>=0))
{
_40.req=dwr.engine._newActiveXObject(dwr.engine._XMLHTTP);
}
Array of XMLHTTP strings
Various XMLHTTP strings from MSXML are stored in array. This facilitates the creation of ActiveXObject that is appropriate for the version of IE.
dwr.engine._XMLHTTP=["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
Function for getting the XMLHttpRequest on older Microsoft browsers
The above code uses a function called _newActiveXObject, which is shown below. This function iterates through the _XMLHTTP array and returns when a successful XMLHTTP object has been created.
dwr.engine._newActiveXObject=function(_99)
{
var _9a;
for(var i=0;i<_99.length;i++)
{
try
{
_9a=new ActiveXObject(_99[i]);
break;
}
catch(ex)
{
}
}
return _9a;
};
Links for XMLHttpRequest
Following are some source code and article links regarding XMLHttpRequest.
Source for XMLHttpRequest Method on window class from ASP.NET AJAX Library
Methods in XMLHttpExecutor class from the Sys.Net Namespace from ASP.NET AJAX Library
Classes from the Sys.Net Namespace from ASP.NET AJAX Library
XMLHttpRequest and AJAX on Google Suggest
XMLHttpRequest and AJAX on maps.live.com
XMLHttpRequest and AJAX on Yahoo
XMLHttpRequest and AJAX on mapquest.com