The user experience brought about by Ajax is obvious to all. With the smallest application, let's try to implement it. Still use the hotheart ajaxrequest class. Start with ASP Ajax in another article.
The implementation result is as follows:
Let's not talk about other things. Look at the Code as follows:
Reg.html
<HTML>
<Head>
<Title> Ajax username detection </title>
<SCRIPT type = "text/JavaScript" src = "ajaxrequest. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR Ajax = new ajaxrequest ();
Function regcheck (){
VaR uname = Document. getelementbyid ("user_name ");
Ajax. Get ("proc_user.asp? Action = regcheck & user_name = "+ uname. Value, usercheck );
}
Function usercheck (OBJ ){
Document. getelementbyid ("msg_user_name"). innerhtml = Unescape (obj. responsetext );
}
</SCRIPT>
</Head>
<Body>
Username: <input type = "text" name = "user_name" id = "user_name"/>
<Button onclick = "regcheck ();"> User Detection </button> <label id = "msg_user_name"> Note: Only admin and shaoyun users in the database </label>
</Body>
</Html>
Proc_user.asp
<! -- # Include file = "conn. asp" -->
<%
Dim action: action = trim (request. querystring ("action "))
Select case action
Case "regcheck"
Dim user_name, ret_string
User_name = trim (request. querystring ("user_name "))
If isreg (user_name) then
Ret_string = escape (user_name & "registered! Enter again! ")
Else
Ret_string = escape (user_name & "not registered! Available! ")
End if
Response. Write ret_string
End select
Function isreg (username)
Dim retval: retval = false
Openconn ("DB. mdb ")
Sqlstr = "select user_name from [user] Where user_name = '" & username &"'"
Call openrs (sqlstr, 1)
If not (Rs. bof and Rs. EOF) Then retval = true
Closers (): closeconn (): isreg = retval
End Function
%>
Note: The above instances require the IIS environment.
Attachment: ajax_usercheck_demo.rar