Bloggers in a small project, to implement a registration form without a refresh to verify the user name or password, but found that no matter how the first pass Ajax verification before the form is not submitted.
For example: a simple validation function
1 function Check () {2 $.post ("#name") ("xxx.php", {user:user}function(msg) {3 if(msg) {returnfalse;} 4 })5 }
1 <form class= "form"Method= "POST"Action= "xxx.php"onsubmit= "return check ()">2 <inputtype= "text"name= "User"ID= "User" />3 <Buttontype= "Submit"value= "Submit"/>4 </form>
Submissions will find that the form is submitted directly without executing the events in the $.post.
There are netizens to solve this:
1, with Blur, after the text box loses focus, transmits the data and verifies, returns the result.
Cons: If the user's browser logs the form information, the user no longer clicks the text box, or the text box cannot be validated after submission.
2, simply do not have to submit, the button to change the type of button, and then add a click function onclick= "Check ()" If the verification through the $ ("form"). Submit () Submission Form
Disadvantage: Cannot use HTML5 authentication.
Bloggers have collected these two ways, if there is a different way, may wish to exchange OH.
Unable to validate solution with Ajax before submitting form