An AJAX validation user name exists

Source: Internet
Author: User

<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)
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.