Tuesday, August 17, 2010

Classic Ajax Using the ActiveX object - XMLHTTP

The follwing code sipnet will gives an overview on the classic way of
 using the ajax call for getting the data from the webserver .

This is the way that we get the data from the web server .
In all the frameworklike the asp.net ajax,jquery Ext,.......are
make use of this.

The following activeX will only work with the IE, not in any other browser



function XmlHttpFunctionExample() {

    if(window.ActiveXObject) {

        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    }

    else {

        xmlhttp = new XMLHttpRequest();

    }

    xmlhttp.open("GET", "Time.aspx", true);

    xmlhttp.onreadystatechange = readyStateChangedHandler;

    xmlhttp.send();    

}


This is the function pointer that actually handles the response form the webserver


function readyStateChangedHandler() {

    if(xmlhttp.readyState == 4) {

        alert(xmlhttp.responseText);

    }    

}
Please see the previous post for the readyState/StatusCode used in web technologies.

0 comments:

Post a Comment