Ajax detects if user name is occupied

Source: Internet
Author: User
Tags date exit empty key return tostring window
Ajax


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 = {



if (ajax.responsetext==1) {
showresult (1, "Your user name can be registered properly")
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 (document.!re.test. 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 ";
}
}
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= '

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.