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