AJAX Implementation in ASP 3.0

Discussion in 'ASP' started by naimish, Jul 3, 2009.

  1. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,043
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth

    Introduction



    To implement AJAX in ASP 3.0.

    Background



    This is a simple application illustrating how AJAX can be implemented in ASP 3.0.

    The code



    Code:
    HTML:
    <html>
     <head>
      <title>Sample AJAX in ASP  </title>
      <script language="javascript">
       var XMLHTTPReq;
       //
       // This is the function that makes an AJAX request to the Server side scripting written in ASP 3.0
       // This function can be enhanced to incorporate any changes to suit any business logic and can
       // be successfully implemented.
       function CheckName()
       {
        var strEmpName = document.all.EmpName.value;
        /* The link to the server side scripting */
        var strURL = "SampleSrv.asp?EmpName=" + strEmpName;
        /* Important: This line initiates the httprequest variable */
        if (window.ActiveXObject) { 
         XMLHTTPReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        /* Important: This segment makes a request to the server */
        if (XMLHTTPReq) 
        {
         XMLHTTPReq.open("POST", strURL, false);
         XMLHTTPReq.send(null);
         var strResults = XMLHTTPReq.responseText; 
        }
        /* The result that is received from the previous segment is used here */
        if (strResults.toLowerCase() == "true") //true. indicating record exists in Database
        {
         alert("This login already exists. Try another name.");
         document.all.EmpName.selected = true;
         document.all.EmpName.focus();
        }
        else
        {
         //Everything is cool and can proceed with getting the rest of the details.
        }
       }
      </script>
     </head>
     <body>
      <table cellspacing=0 cellpadding=3 border=1>
       <tr><td colspan=2><CENTER><B>Enter your Login Details</B></CENTER></td></tr>
       <tr><td>Login:</td><td><input type="Text" name="EmpName" value="" onblur="CheckName();"></td></tr>
       <tr><td>Password:</td><td><input type="Text" name="pwd" value=""></td></tr>
       <tr><td>Re-enter Password:</td><td><input type="Text" name="pwd1" value=""></td></tr>
       <tr><td>Qualification:</td><td><input type="Text" name="Qualif" value=""></td></tr>
       <tr><td>Address:</td><td><input type="Text" name="Add" value=""></td></tr>
       <tr><td>City:</td><td><input type="Text" name="City" value=""></td></tr>
       <tr><td>Country:</td><td><input type="Text" name="Country" value=""></td></tr>
       <tr><td colspan=2></td></tr>
       <tr><td colspan=2 align=center><input type="button" value="Submit" onclick="alert('Non-functional!')"></td></tr>
      </table>
     </body>
    </html>
    
     
  2. LenoxFinlay

    LenoxFinlay Banned

    Joined:
    Apr 15, 2009
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    You've heard of it. It is the latest buzz term for web programmers these days. AJAX is an acronym that stands for Asynchronous JavaScript and XML. AJAX gains its popularity by allowing data on a page to be dynamically updated without having to make the browser reload the page. I will describe more about how AJAX works, and then go into some sample code to try out.
    This term has been made famous by some of Google's latest web apps. At the top of this list is Google Suggest, which gives you suggestions (go figure) on what you are searching for as you type based on popularity of the search term. If you aren't familiar with Google Suggest, check it out.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice