Jquery ajax checks whether the user name exists during user registration

Source: Internet
Author: User

Start with a New Year's page. It is currently called grade.htm.
This file requires the introduction of two files: jquery. js (jquery framework file) and grade. js (verified individual files ).
The following input is used to enter the username. id = "gradeInfo" is used to display prompt information.
Grade.htm Copy codeThe Code is as follows: <input type = "text" size = "6" name = "NAME" id = "NAME"/> <font color = "red"> * </font>
<Span id = "gradeInfo"> </span>

After entering the information, the user enters the verification process to see how grade. js was written for verification.
Grade. jsCopy codeThe Code is as follows :/**
* Verify that the user name is duplicated in js
*
* @ Name grade. js
* @ Author jason <msn: x334@eyou.com>
* @ Use verify whether the user name exists
* @ Todo
*/
$ (Document). ready (function (){
CheckConfirm ();
});
// Verify whether the user name exists
Function checkConfirm (){
$ ("# NAME"). blur (function (){
Var gradename = $ (this). val ();
Var changeUrl = "GradeAdmin. php? Action = check & gradename = "+ gradename;
$. Get (changeUrl, function (str ){
If (str = '1 '){
$ ("# GradeInfo" ).html ("<font color = \" red \ "> the user name you entered exists! Enter again! </Font> ");
} Else {
$ ("# GradeInfo" ).html ("");
}
})
Return false;
})
}

In the above section of the js file, I will only explain a few key points.
1. $ ("# NAME" ).blur's meaning is that the action is triggered after the form with id NAME in grade.htm is input.
2. $ (this). val () indicates that the value in the form with id as NAME is obtained.
3. $. get (changeUrl, function (str) indicates that after running ajax, changeUrl is the address of the program to be connected, and str is the program
The display structure obtained after calculation.
4. $ ("# gradeInfo" ).html means to write html files to the tag whose id is gradeInfo. The label whose id is gradeInfo refers
In grade.htm.
Let's take a look at the calculation form of GradeAdmin. php.
GradeAdmin. php
Copy codeCopy codeThe Code is as follows: if ($ frm_action = 'check ')
{
$ GradeName = $ _ GET ['gradename'];
$ GradeAdminObj = new Services_GradeAdmin ($ db );
// Determine whether or not the username entered in the database is determined based on $ gradeName. If yes, 1 is returned. If
If no value exists, 0 is returned. The returned value is uploaded to grade. js.
$ GradeCheck = $ gradeAdminObj-> getGradeByName ($ gradeName );
If (is_numeric ($ gradeCheck )){
Echo '1 ';
} Else {
Echo '0 ';
}
Exit ();
}

This is to determine whether the user name already exists during user registration.

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.