Thursday 13 October 2011

Ajax Example

 in the javascript function write the below code

function test()
{

var clientname=document.getElementbyId("client").value;
var password=document.getElementbyId("password").value;
var url = "ajaxpage.aspx";
var pars = "client=" + clientname + "&password=" + password;



    var myAjax = new Ajax.Request(url, {
        method: 'post', postBody: pars,
        onSuccess: function(n) {
        if (n.responseText == "success") {
          
               var a = "Record inserted successfully"
               window.location.href = "testing.aspx?msg=" + a;
           
            }
            else if (n.responseText == "success1") {
                      var a = "Record Updated Successfully"
            window .location .href = "testing.aspx;
            //alert("Updated Successfully");
            }
            else {
                               alert(n.responseText);
                           }
        },
        onFailure: function(n) {
               alert ("failure");
            document.body.style.cursor = "";
        }
    });
    return false;
}

In the ajax URL page write,write the below code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" Debug="true" %>
<%  Response.AddHeader("Cache-Control", "no-cache, must-revalidate")%>
<%  Response.AddHeader("Pragma", "no-cache")%>