Friday, July 22, 2011

A Forgotten Story - Ajax in ASP.NET using JavaScript

http://blogs.cametoofar.com/post/raw-or-plain-ajax-in-aspnet-using-javascript.aspx


<script type="text/javascript">
    function sendViaAjax() {
 
        // Build URL to make Ajax call
        var url = "Test.aspx?name=" + document.getElementById("txtName").value;
 
        // Creates an Ajax call object
        var xmlHttp; = new XMLHttpRequest();
 
        // Specify URL to connect
        xmlHttp.open("GET", url, true);
 
        // Callback function to handle response from Server
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    alert(xmlHttp.responseText);
                }
            }
        };
 
        // Send Ajax request to Server
        xmlHttp.send();
    }
</script>

protected void Page_Load(object sender, EventArgs e)
{
    string ajxValue = "Hello " + Request.QueryString["name"] + " !";
 
    Response.Write(ajxValue);   // Write the Response
    Response.End(); // End Response
}

No comments:

Post a Comment