Php+jquery+ajax Implementing User Name Verification

Source: Internet
Author: User

In most cases, the writing of jquery code requires that we put jquery code in any of the following three types of function. There are three kinds of writing, the same effect, a bit like window.onload, but there are different, that is, Window.onload is the page after loading will not be executed,
and $ (document). The Ready () method simply waits for all tags to be loaded, and then the $ (document). Ready () can be called multiple times,
The window.onload cannot be overridden by a subsequent call. The first type: $ (document). Ready (function () {...}); The second type: $ (). Ready (function () {...}); The third type: $ (function () {...}); Note: The event handlers registered through the $ (document) method in jquery can be called as long as the DOM is fully ready.
For example, a picture as long as the label is complete, do not wait for the picture to be loaded, you can set the image of the width of the property or style, etc. And see how Ajax operates in jquery? Ajax is passed in two ways:get/post "get Mode"

"Post Mode"

var username = $ (this). Val (); var url = "checkuser.php"; $.post (url,{name:username},function (Result) {...}

jump to the checkuser.php page after receiving it via get/post and judging from the database if it exists, then return a value ... HTML code:

User name:

<form action= "" method= "post" > <input type= "text" name= "username" value= ""/> <input type= "Submit" value= "Submit"/></form>
jquery Code:

$ ("#userName"). blur (function () {var userName = $ (this). Val (); var url = "checkuser.php";        Jump to Judgment page//below is run Ajax, go to Changeurl page, pass in name, return result $.post (URL, {name:username},function (result) {if (result = = ' 1 ') { $ ("#Info"). HTML ("User name exists!    "); }else{$ ("#Info"). HTML ("can register!    "); }   }) })
checkuser.php
if ($_post[' name ')) {//Receive POST pass-through value $username = Trim ($_post[' name ');  To judge, originally to be taken from the database, I lazy a bit, just test ...  if ($username = = "Admin") {echo ' 1 ';  }else{echo ' 0 '; }}
?>

Php+jquery+ajax Implementing User Name Verification

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.