{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 Yahoo
Summary
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.
 
Table of Contents

Getting the XMLHttpRequest Object from Yahoo Maps

Code Listing 1. Getting the XMLHttpRequest Object from Yahoo Maps

Analyzing the XMLHttpRequest Code used on Yahoo Maps

Figure 1. Analysis of Creating XMLHttpRequest Object on Yahoo Maps

Get the XMLHttpRequest on newer browsers

Get the XMLHttpRequest on older Microsoft browsers

Array of XMLHTTP strings

Getting the XMLHttpRequest Object from Yahoo Mail

Code Listing 2. Getting the XMLHttpRequest Object from Yahoo Mail

Analyzing the XMLHttpRequest Code used on Yahoo Mail

Figure 2. Analysis of Creating XMLHttpRequest Object on Yahoo Mail

Get the XMLHttpRequest object on newer browsers

Get the XMLHttpRequest object on older Microsoft browsers

XMLHTTP variable

Links for XMLHttpRequest

 
Article Series
Previous Article:
XMLHttpRequest and AJAX on maps.live.com
This article is part of the Series:
Article Series: XMLHttpRequest and AJAX on Popular Sites
Next Article:
XMLHttpRequest and AJAX on mapquest.com

Getting the XMLHttpRequest Object from Yahoo Maps

The following code is used on Yahoo Maps to obtain the XMLHttpRequest object on a given web browser.

Code Listing 1. Getting the XMLHttpRequest Object from Yahoo Maps

createXhrObject:function(E)
{
    var D,A;
    try
    {
        A=new XMLHttpRequest();
        D={conn:A,tId:E};
    }
    catch(C)
    {
        for(var B=0;B<this._msxml_progid.length;++B)
        {
            try
            {
                A=new ActiveXObject(this._msxml_progid[B]);
                D={conn:A,tId:E};
                break;
            }
            catch(C)
            {
            }
        }
    }
    finally
    {
        return D;
    }
}

_msxml_progid:["Microsoft.XMLHTTP","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP"]

Analyzing the XMLHttpRequest Code used on Yahoo Maps

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

Figure 1. Analysis of Creating XMLHttpRequest Object on Yahoo Maps

Figure 1. Analysis of Creating XMLHttpRequest Object on Yahoo Maps

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).

var D,A;
try
{
    A=new XMLHttpRequest();
    D={conn:A,tId:E};
}

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 (_msxml_progid) 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.

for(var B=0;B<this._msxml_progid.length;++B)
{
    try
    {
        A=new ActiveXObject(this._msxml_progid[B]);
        D={conn:A,tId:E};
        break;
    }
    catch(C)
    {
    }
}

Array of XMLHTTP strings

Various XMLHTTP strings from MSXML are stored in array (outside the above function). This facilitates the creation of ActiveXObject that is appropriate for the version of IE.

_msxml_progid:["Microsoft.XMLHTTP","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP"]

Getting the XMLHttpRequest Object from Yahoo Mail

Following is yet another way of getting the XMLHttpRequest object. This time, it’s on Yahoo Mail.

Code Listing 2. Getting the XMLHttpRequest Object from Yahoo Mail

_newHTTP: function(bt)
{
    var ret = null, e;

    try
    {
ret = new XMLHttpRequest();
    }
    catch (e)
    {
        e = ret = null;
    }
    
if (!ret)
        try
        {
ret = new ActiveXObject(activeX.xmlhttp);
        }
        catch (e)
        {
            ret = null;
        }
        
return (bt) ? {err:e,msg:"xmlhttp:failure\n"} : ret;
}

xmlhttp:’MSXML2.XMLHTTP.3.0’

Analyzing the XMLHttpRequest Code used on Yahoo Mail

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

Figure 2. Analysis of Creating XMLHttpRequest Object on Yahoo Mail

Figure 2. Analysis of Creating XMLHttpRequest Object on Yahoo Mail

Get the XMLHttpRequest object on newer browsers

By using new XMLHttpRequest(), create a new variable on the newer versions of the popular browsers.

var ret = null, e;

try
{
    ret = new XMLHttpRequest();
}

Get the XMLHttpRequest object on older Microsoft browsers

For the older IE browsers, use the ActiveXObject.

try
{
    ret = new ActiveXObject(activeX.xmlhttp);
}

XMLHTTP variable

Here the XMLHTTP from MSXML is stored as a variable outside the function.

xmlhttp:’MSXML2.XMLHTTP.3.0’

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 maps.live.com
This article is part of the Series:
Article Series: XMLHttpRequest and AJAX on Popular Sites
Next Article:
XMLHttpRequest and AJAX on mapquest.com
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-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.
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