CopyCode The Code is as follows: // check whether the user name is occupied
Function Geto (){
VaR Ajax = false;
Try {
Ajax = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Ajax = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = 'Undefined '){
Ajax = new XMLHttpRequest ();
}
Return Ajax;
}
Function getresult (serverpage ){
VaR Ajax = Geto ();
VaR Sep = (-1 <serverpage. indexof ("? "))? "&":"? "
VaR newurl = serverpage + Sep + "__=" + encodeuricomponent (new date (). tostring ());
Ajax. Open ("get", newurl, true );
Ajax. onreadystatechange = function (){
If (Ajax. readystate = 4 & Ajax. Status = 200 ){
If (Ajax. responsetext = 1 ){
Showresult (1, "your user name can be registered normally ")
Ajaxresult = true;
} Else {
Showresult (0, "your user name is occupied ")
Ajaxresult = false;
}
}
}
Ajax. Send (null );
}
Function chkusername (){
VaR sflag; // tag;
VaR serr; // error message;
Sflag = true;
VaR Re =/^ \ W {2, 20} $ /;
If (! Re. Test (document. form1.username. Value )){
Sflag = false;
Serr = "the user name can only contain letters, numbers, or underscores ";
}
If (document. form1.username. value. length> 20 | document. form1.username. value. Length <2 ){
Sflag = false;
Serr = "username length must be 2 ~ Between 20 characters ";
}
If (document. form1.username. value = ""){
Serr = "username cannot be blank ";
Sflag = false;
}
// Ajax detection returned results
If (! Sflag ){
Showresult (0, serr)
} Else {
Getresult ("../membercheck. aspx? T = 1 & name = "+ document. form1.username. value );
}
// Document. getelementbyid ("spname"). innerhtml = SS;
}
Function showresult (TAG, STR ){
VaR OBJ = Document. getelementbyid ("spname ");
If (TAG = 0 ){
OBJ. style. Border = "1px solid red ";
OBJ. style. color = "red ";
} Else {
OBJ. style. Border = "1px solid green ";
OBJ. style. color = "green ";
}
OBJ. innerhtml = STR;
OBJ. style. Padding = "1px ";
}
// Obtain the user question value returned by Ajax
Function getquestiondata (spage ){
VaR Ajax = Geto ();
VaR Sep = (-1 <spage. indexof ("? "))? "&":"? "
VaR newurl = spage + Sep + "__=" + encodeuricomponent (new date (). tostring ());
Ajax. Open ("get", newurl, true );
Ajax. onreadystatechange = function (){
If (Ajax. readystate = 4 & Ajax. Status = 200 ){
If (Ajax. responsetext = ""){
Document. getelementbyid ("getstate"). innerhtml = "the user does not exist! "
}
Else {
Document. G. Question. value = Ajax. responsetext;
Document. G. Question. readonly = true;
Document. getelementbyid ("getpwdstep1"). style. Display = "NONE ";
Document. getelementbyid ("getpwdstep2"). style. Display = "Block ";
Document. getelementbyid ("getstate"). innerhtml = "";
}
}
}
Ajax. Send (null );
}
Function getuserq (){
// Change the display style of the error Span
Document. getelementbyid ("getstate"). style. Padding = "1px 4px ";
If (document. G. username. value = ""){
Document. getelementbyid ("getstate"). innerhtml = "the user name cannot be blank! "
} Else {
Document. getelementbyid ("getstate"). style. Background = "red ";
Document. getelementbyid ("getstate"). style. color = "white ";
Document. getelementbyid ("getstate"). innerhtml = "loading data ...";
// Set Ajax
Getquestiondata ("../membercheck. aspx? T = 2 & gname = "+ document. G. username. value );
}
}
Function login (N, P, T)
{
If (t = false ){
Document. getelementbyid ("plogin"). style. Display = "NONE ";
Document. getelementbyid ("logininfo"). innerhtml = "logging in for you. Please wait ...";
}
VaR request;
If (undefined = request ){
Request = new request ();
}
If (undefined = request. _ Get ){
// Ajax is not supported to obtain data;
If (t = false ){
Document. getelementbyid ("plogin"). style. Display = "";
Document. getelementbyid ("logininfo"). innerhtml = "data cannot be obtained ";
}
}
Else {
Username = N;
Toprev = T;
Request. getnocache (loginpath + "logincheck. aspx" + "? N = "+ N +" & P = "+ P, logincheck );
}
}
Function logincheck (result)
{
If (result. readystate! = Readystate. Complete)
Return;
// Obtained successfully;
If (result. Status = httpstatus. OK & result. responsetext! = "")
{
// Execute the returned statement;
// Alert (result. responsetext );
If (result. responsetext = '1 ')
{
If (toprev = false ){
Document. getelementbyid ("logininfo "). innerhtml = '<ul> <li> Welcome' + username + '</LI> <li> <a href = "' + loginpath + 'Member/"> management </> </LI> <li> <a href = "'+ loginpath +' logout. aspx "> exit </a> </LI> </ul> ';
}
Else {
If (urlprev! = ''){
Document. Location. href = urlprev;
}
Else {
Document. Location. href = loginpath;
}
}
Return;
}
Else
{
If (document. Location. href! = "Http: //" + document. Location. hostname + loginpath + "Member/login. aspx ")
Document. Location. href = loginpath + "Member/login. aspx ";
}
}
Else
{
// Failed;
Document. Location. href = loginpath + "Member/login. aspx ";
Return;
}
}
Function checkkey (caputurekey, N, P, T ){
Var key = Window. event. keycode;
If (Key = caputurekey ){
Login (N, P, T );
}
}
Function setlogininfo (blogin ){
If (blogin ){
Document. getelementbyid ("logininfo "). innerhtml = '<ul> <li> Welcome' + username + '</LI> <li> <a href = "' + loginpath + 'Member/"> management </> </LI> <li> <a href = "'+ loginpath +' logout. aspx "> exit </a> </LI> </ul> ';
}
Else {
}
}
Function gotourl (s ){
Window. Location. href = loginpath + 'Member/reguser.html ';
}