After JQuery is verified, use ajax to submit data.

Source: Internet
Author: User

After JQuery is verified, use ajax to submit data.

1 function checkForm () {2 validator = $ ("# commentForm "). validate ({// # formId is the ID of the form to be verified 3 errorElement: "span", // error marked with "div" label, default: "label ", "span" is displayed on the right of the text box by default. // wrapper: "li", // use the "li" label and package the preceding errorELement. 5 // errorClass: "validate-error", // the css class name for the error prompt "error" 6 // onsubmit: false, // whether to verify when the form is submitted. The default value is: true 7 // onfocusout: false, // whether to verify when you obtain the focus. Default Value: true 8 // onkeyup: false, // whether to verify when you press the keyboard. Default Value: true 9 // onclick: f Alse, // whether to verify when you click the mouse (usually checkbox, radiobox) 10 // focusCleanup: false, // when the element that fails to pass the verification gets the focus, and remove the error message. The default is false11 // focusInvalid: true, // form that fails verification after the form is submitted (the first form that has not passed verification or submitted the previous focus) will get the focus, the default true12 // ignore: "# cname" // some elements are not verified, the value corresponds to the selector, if you need to ignore multiple text boxes, you can use the class selector 13 ignoreTitle: true, 14 validClass: "valid", // when the verification is successful, the css class name 15 success: function (label) is used) {// The prompt message 16 label is used when the verification is successful. addClass ("valid" pai.html ("OK! ") 17}, 18 submitHandler: function (form) {// If the verification succeeds, click the submit button to perform the operation. Note: After using this method, action = "xx" in form will expire 19 alert ('verification passed '); 20}, 21 invalidHandler: function (form, validator) {// If the verification fails, perform the following operations: 22. var errors = validator. numberOfInvalids (); // get the total number of errors 23 var message = 'your exist' + errors + 'error'; 24 // alert (message); 25}, 26 rules: {27 "x. name ": {// enter name28 required: true, // verification condition: 29 minlength3: 5, // verification condition: the minimum length is 530. maxlength3: 10, 31 checkCharType: [true, false, false, null] 32}, 33 "x. sex ": {// input box for verification name34 required: true, // verification condition: required 35 minlengty2: 5, // verification condition: Minimum Length: 536 maxlengty2: 1037}, 38}, 39 messages: {40 "x. name ": {41 required:" cannot be blank ", 42 minlength:" minimum value: 5 "43}, 44" x. sex ": {45 required:" cannot be blank ", 46 minlength:" minimum value: 5 "47} 48} 49}); 50} 51 52 function xx () {53 // alert ($ ("# commentForm "). validate (). form (); // executes form Verification and determines whether the verification is successful. If the verification succeeds, true is returned; otherwise, false54 $ ("# commentForm") is returned "). valid (); // $ ("# commentForm "). valid () indicates to run form verification 55} 56 57 function cl () {58 $ ("# commentForm "). validate (). resetForm (); // clear all error messages 59}

Reproduced to: http://blessht.iteye.com/blog/1074419

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.