jquery Ajax detects if a user's name exists while registering

Source: Internet
Author: User
Tags php tutorial

This file requires the introduction of two file Jquery.js (jquery framework files) and grade.js (validated individual files).
The following input is used to enter the user name, and id= "Gradeinfo" is used to display the hint information.
grade.htm
Copies code code as follows:
<input type= "text" size= "6" name= "name" id= "name"/><font color= "Red" >* </font>
<span id= "Gradeinfo" ></SPAN>

When the user enters the information, enter the validation link to see how our verification grade.js is written.
Grade.js
Copies code code as follows:
/**
* Verify user name is duplicated JS
*
* @name grade.js
* @author Jason<msn:x334@ey Ou.com>
* @use Verify that the username exists
* @todo
*/
$ (document). Ready (function () {
checkconfirm ();
});
//Verify that the user name exists
function checkconfirm () {
$ ("#name"). blur (function () {
var gradename = $ (this). Val ();
var changeurl = "gradeadmin.php tutorial? action=check&gradename=" +gradename;
$.get (changeurl,function (str) {
if (str = ' 1 ') {
$ ("#gradeinfo"). HTML ("<font color=" Red "> The username you entered exists! Please re-enter! </font> ");
}else{
$ ("#gradeinfo"). HTML ("");
}
})
return false;
})

The above JS file, I only explain a few more key places.
1. $ ("#name"). The meaning of Blur is to trigger an action when the form with ID name in the grade.htm is finished.
2, $ (this). Val () means to get the value in the form with ID name.
3, $.get (str) meaning is: After running Ajax, Changeurl is to connect the program address, STR is the program
The display structure that is obtained after the calculation is completed.
4. $ ("#gradeinfo"). The meaning of HTML is to write an HTML file to a label with an ID of gradeinfo. A label with an ID of gradeinfo means
Grade.htm in the ID of the Gradeinfo, the display of the content will appear again in the location of the tag.
Then look at the gradeadmin.php of the calculation form.
gradeadmin.php
Copy Code
Copy code code as follows:
if ($frm _action = = ' Check ')
{
$gradename = $_get[' gradename '];
$gradeadminobj = new Services_gradeadmin ($DB);
According to $gradename to determine whether the database tutorial exists in the user name filled in, if there is a return of 1, if
Does not exist returns 0, this return value is passed to Grade.js.
$gradecheck = $gradeadminobj->getgradebyname ($gradename);
if (Is_numeric ($gradecheck)) {
echo ' 1 ';
}else{
echo ' 0 ';
}
Exit ();
}

This is the question of whether or not the user name exists when the user registers

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.