<script language= "Web Effects" type= "Text/javascript" >
<!--
function Checkusername (username) {
Building a XMLHttpRequest object across browsers
var xmlhttp;
try{
xmlhttp= new ActiveXObject (' msxml2.xmlhttp ');
}catch (e) {
try{
xmlhttp= new ActiveXObject (' microsoft.xmlhttp ');
}catch (e) {
try{
xmlhttp= new XMLHttpRequest ();
}catch (e) {}
}
}
Create the request and use escape to encode the username to avoid garbled
Xmlhttp.open ("Get", "Checkusername.asp?username=" +escape (username));
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4) {
if (xmlhttp.status==200) {
To determine whether a user name exists based on ResponseText
if (xmlhttp.responsetext== "1") alert ("Sorry, the username exists!") ");
Else alert ("Congratulations!") The user name is not registered! ");
}else{
Alert ("Network failure. ");
}
}
}
Xmlhttp.send (NULL);
}
-->
</script>
ASP. File
<%
Dim conn,rs
Dim connstr
Dim sqlcmd
Dim username
' Get user Name query string
Username=request.querystring ("username")
' Create a Database Tutorial connection object and open
Set Conn=server.createobject ("Adodb.connection")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Data.mdb")
Conn.Open ConnStr
' Create a DataSet object
Set Rs=server.createobject ("Adodb.recordset")
' Query for records with user name equal to specified value
sqlcmd= "SELECT ID from user where username= '" & Username & "'"
Rs=conn.execute (sqlcmd)
Defines a variable to indicate whether the user name exists
Dim exist
Determine if a user name exists based on whether there is data
If Rs.eof then exist=1 else exist=0
To close a database connection
Rs.close
Conn.close
Set rs=nothing
Set conn=nothing
Returns the result
Response.Write (exist)
%>