{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 maps.live.com
Summary
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.
 
Table of Contents

Getting XMLHttpRequest Object

Code Listing 1. Getting the XMLHttpRequest Object from maps.live.com

XMLHttpRequest Code Analysis from maps.live.com

Figure 1. Analysis of Creating XMLHttpRequest Object on Live.com Maps

Get the XMLHttpRequest object on newer browsers

Get the XMLHttpRequest object on older Microsoft browsers

Links for XMLHttpRequest

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

Getting XMLHttpRequest Object

The following JavaScript function is used on the maps.live.com web page in order to get hold of the XMLHttpRequest object, which is used to communicate asynchronously with the maps web server.

Code Listing 1. Getting the XMLHttpRequest Object from maps.live.com

function GetXmlHttp()
{
    var a=null;
    
    if(window.XMLHttpRequest)
        a=new XMLHttpRequest;
        
    else if(window.ActiveXObject)
    try
    {
        a=new ActiveXObject("Msxml2.XmlHttp.6.0")
    }
    catch(b)
    {
        try
        {
            a=new ActiveXObject("Msxml2.XmlHttp.3.0")
        }
        catch(c)
        {
            try
            {
                a=new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch(d)
            {
                try
                {
                    a=new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch(e)
                {
                }
            }
        }
    }
    
    else
        throw"XMLHTTP Required: Browser not supported";
        
    return a
}

If you look at the source behind maps.live.com, the above code would be buried in a gigantic listing of JavaScript, which is basically one long string without any formatting.

This ‘release’ version of JavaScript has been optimized for size. All the comments inside the JavaScript have been removed. The variable names have been drastically shortened (for example, notice ‘a’ for the XMLHttpRequest object). Unnecessary spaces have been removed. Unneeded semi-colons (;) at the end of the lines have been removed.

However, with a little bit of manual formatting, you can see what maps.live.com is doing to obtain XMLHttpRequest object.

XMLHttpRequest Code Analysis from maps.live.com

The following figure shows various sections of the function that creates the XMLHttpRequest object for a given web browser on the live.com Maps page.

Figure 1. Analysis of Creating XMLHttpRequest Object on Live.com Maps

Figure 1. Analysis of Creating XMLHttpRequest Object on Live.com Maps

Get the XMLHttpRequest object on newer browsers

By using new XMLHttpRequest(), create a new variable on the newer versions of the popular browsers. Here the code looks for XMLHttpRequest object in window object (which is by default the global object).

if(window.XMLHttpRequest)
    a=new XMLHttpRequest;

Get the XMLHttpRequest object on older Microsoft browsers

For the older IE browsers, use the ActiveXObject. Again, here the code looks for a global ActiveXObject (global meaning window). A series of checks are done for XMLHTTP objects on MSXML.

else if(window.ActiveXObject)
try
{
    a=new ActiveXObject("Msxml2.XmlHttp.6.0")
}
catch(b)
{
    try
    {
        a=new ActiveXObject("Msxml2.XmlHttp.3.0")
    }
    catch(c)
    {
        try
        {
            a=new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch(d)
        {
            try
            {
                a=new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch(e)
            {
            }
        }
    }
}

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 Google Suggest
This article is part of the Series:
Article Series: XMLHttpRequest and AJAX on Popular Sites
Next Article:
XMLHttpRequest and AJAX on Yahoo
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-mapquest-get-object.jpg
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).
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