//here we are declaring a global variable Xmlhttp or it can be anything
var Xmlhttp = false;

//we are trying to create an XMLHttpRequest Object using try catch method
try
    {
        //This statement is to create an activex object for the internet explorer with version greater than 5
        Xmlhttp = new ActivexObject("Msxml2.XMLHTTP");
        //alert("XmlObject Created And You Are Using Microsoft Internet Explorer With Version Greater Than 5");
    }
    //if any error occurs in creating an activex object for the internet explorer with version > 5 then this block executes
    //this block will catch the error which occured in the try block
    catch(e)
    {
        //In this block we again are trying to create an activex object for internet explorer with version < 5
        try
        {
            //This statement is to create an activex object for internet explorer with version < 5
            Xmlhttp = new ActivexObject("Microsoft.XMLHTTP");
            //alert("XmlObject Created And You Are Using Microsoft Internet Explorer With Older Version Lass Than 5");
        }
        catch(e)
        {
            //if the browser is not internet explorer the ctrl comes here
            //And now still no xmlhttp object is not created
            Xmlhttp = false;
            //alert("No XmlObject Created BCOZ This Is Not Microsoft Internet Explorer");
        }
    }
//here we are checking that is the xmlhttprequest object is created or not     
//In the case of mozilla and safari (!Xmlhttp) will return true
//(typeof XMLHttpRequest != 'undefined') will return true for Firefox and Safari so we can create an object.
if(!Xmlhttp && typeof XMLHttpRequest != 'undefined')
{
//now we are creating a xmlhttprequest object for the firefox and safari,opera etc...
Xmlhttp = new XMLHttpRequest();
//alert("XmlObject Created And You Are Not Using Microsoft Internet Explorer");
}

//Now we have an xmlhttprequest object in our hands
//here we are defining a function with 2 args the first one is the name of the page to be loaded
//and the second one is the id where the content has to be loaded
function MyRequest(ServerPage,objID)
{
//alert(ServerPage);
//alert(objID);

//now we fetch the div id passed into the function and assign it to the obj variable
var obj = document.getElementById(objID);

//Now we open a connection to a particular file on the server
//GET is the method used for receiving information from the server
//POST is used when we are sending information to the server
Xmlhttp.open("GET",ServerPage);

    //onreadystatechange is an eventhandler which allows us to trigger a function or
    //a block of code which is done whenever the readyState = 4(complete)
    //here in this we are triggering a function
    Xmlhttp.onreadystatechange = function()
    {
        //we are displaying the readyState code
        //alert("Now The readyState Is = "+Xmlhttp.readyState);
       
        //checking if the readyState is 'complete' and status is 'ok'
        if(Xmlhttp.readyState == 4 && Xmlhttp.status == 200)
        {
            //the responseText property will contain the output of the script returned from the server
            //the innerHTML property of the 'id' will hold the text present inside the id
            //here 'obj' is the handler to the 'id' of the div tag           
            //Now we are redirecting the 'responseText' which we got from the server into the 'innerHTML' text
            obj.innerHTML = Xmlhttp.responseText;
        }
    }
//The send() method sends the request to the server.
//Once the request is sent back the onreadystatechange event is fired.
Xmlhttp.send(null);
}