Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » Ajax » General » Downloads
 

Backbone of Ajax: XmlHttpRequest

By , 2 Nov 2007
 
article_src.zip
Article_src
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Calling an another page</title>
    <script language="javascript" type="text/javascript">
    
    //Creating the instanse of the XmlHttpRequest
    // branch for native XMLHttpRequest object
    var client=null;
    if (window.XMLHttpRequest) 
    {
        client = new XMLHttpRequest();
    } // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject) 
    {
        client = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    //sending information to server
    function doCall()
    {
        try
        {
        client.onreadystatechange = callBack;
        client.open("GET", document.getElementById("txtURL").value);
        client.send();
        }catch(ex)
        {
        alert(ex.message);
        }
    }
    
    //waiting and processing server response
    function callBack(response)
    {
        try
        {
            if(client.readyState == 4 && client.status == 200) 
            {
            document.getElementById("panel").innerHTML=client.responseText;
            }
         }
        catch(ex)
         {
         alert(ex.message);
         }
    }
    </script>
</head>
<body>
<h4>Reading server responseUsing XMLHttpRequest</h4>
Server URL: <input id="txtURL" type="text" value="HtmlPage2.htm" />
<input type="button"  value="Call" onclick="doCall()" />
<br />[Output]
<hr />
<div id="panel"></div>
<hr />
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of use and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Manikandan.net
Web Developer
India India
Member
"Manikandan Balakrishnan" Working as an IT consultant with LogicaCMG’s Global Service Delivery part-India, he has a good experience on Web/Win development (C#, Asp.net) and enterprise application integration (BizTalk) technologies. Prior to this he worked on world’s biggest e-learning product with Excel Soft Technologies, Mysore.
 
City: Coimbatore, TN
CreativeManix@gmail.com

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 2 Nov 2007
Article Copyright 2007 by Manikandan.net
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid