Copy Code code as follows:
Detect if 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 properly")
Ajaxresult=true;
}else{
Showresult (0, "Your username 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= "User name can only enter letters, numbers or underscores";
}
if (document. form1.username.value.length>20| | Document. FORM1.USERNAME.VALUE.LENGTH<2) {
Sflag=false;
Serr= "username length must be between 2~20 characters";
}
if (document. form1.username.value== "") {
serr= "User name cannot be empty";
Sflag=false;
}
Ajax Detection Returns 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";
}
Fetch the user problem 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= "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= "User name cannot be empty!"
}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= "is helping you login, please wait ...";
}
var request;
if (undefined = = Request) {
Request = new request ();
}
if (undefined = = Request._get) {
Ajax fetch data is not supported;
if (T==false) {
document.getElementById ("Plogin"). style.display= "";
document.getElementById ("Logininfo"). Innerhtml= "Cannot obtain data";
}
}
else{
Username=n;
toprev=t;
Request. Getnocache (Loginpath + "logincheck.aspx" + "? n=" + N + "&p=" + P,logincheck);
}
}
function Logincheck (Result)
{
if (Result.readystate!=readystate.complete)
Return
Successful acquisition;
if (Result.status==httpstatus.ok && result.responsetext!= "")
{
Executes 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/" > Admin </a></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/" > Admin </a></li><li><a href= "' + Loginpath + ' logout.aspx ' > Exit < /a></li></ul> ';
}
else{
}
}
function Gotourl (s) {
Window.location.href=loginpath + ' member/reguser.html ';
}