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 Code:
<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>

