{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
XMLHttpRequest and AJAX on mapquest.com
Summary
This article looks at how the JavaScript code on mapquest.com gets the XMLHttpRequest object. Here are code looks for XMLHttpRequest or ActiveXObject global objects (i.e. on the window).
 
Table of Contents

Getting XMLHttpRequest Object

Code Listing 1. Getting the XMLHttpRequest Object from mapquest.com

XMLHttpRequest Code Analysis from mapquest.com

Figure 1. Analysis of Creating XMLHttpRequest Object on mapquest.com

Get the XMLHttpRequest on newer browsers

Get the XMLHttpRequest on older Microsoft browsers

Array of XMLHTTP strings

Function for getting the XMLHttpRequest on older Microsoft browsers

Links for XMLHttpRequest

 
Article Series
Previous Article:
XMLHttpRequest and AJAX on Yahoo
This article is part of the Series:
Article Series: XMLHttpRequest and AJAX on Popular Sites
Next Article: This is the Last Article of the Series

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

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

Article Series
Previous Article:
XMLHttpRequest and AJAX on Yahoo
This article is part of the Series:
Article Series: XMLHttpRequest and AJAX on Popular Sites
Next Article: This is the Last Article of the Series
Bookmark and Share This

More Articles With Similar Tags
icon-ajax-xmlhttprequest-google-suggest.jpg
This article looks at how Google Suggest uses the XMLHttpRequest object in order to provide the real-time search suggestions in an AJAX way. The actual JavaScript code used to get the XMLHttpRequest object and the function that’s called on onreadystatechange are discussed.
icon-ajax-xmlhttprequest-yahoo-maps-get-object.jpg
This article looks at the code that creates XMLHttpRequest object on the Yahoo Maps and Yahoo Mail pages. This code has a clever way of iterating through the ActiveX objects on older Microsoft browsers.
icon-ajax-xmlhttprequest-live-maps-get-object.jpg
This article looks at how maps.live.com gets the XMLHttpRequest object on a given browser. It looks for either the XMLHttpRequest global object on window or looks for ActiveXObject.
This series of articles looks at how popular sites use XMLHttpRequest object in their JavaScript to provide the AJAX functionality. These articles take a look at the actual JS code used on these popular sites like Google Suggest, Yahoo, Live.com, and MapQuest.
About  Contact  Privacy Policy  Site Map