Use of the jQuery form plug-in -- use the formData parameter to verify the form and then submit (simple verification)., jqueryformdata

Source: Internet
Author: User

Use of the jQuery form plug-in -- use the formData parameter to verify the form and then submit (simple verification)., jqueryformdata

The Form Plugin API provides many useful methods for you to easily process the data and Form submission processes in the Form.

Test Environment: A web project deployed in Tomcat.

 

1. Introduce dependency js

 

 <script src="jquery-1.3.1.js" type="text/javascript"></script>   <script src="jquery.form.js" type="text/javascript"></script>

 

 

Ii. initialize the callback function.

First, initialize the form and give itbeforeSubmitCallback Function-this is a function used for verification.

 

$ (Document ). ready (function () {$ ('# myForm '). ajaxForm ({target: '# output1', // update the content with the id output1 returned by the server. beforeSubmit: validate // verification before submission });});

 

 

Iii. validation rules

 

Function validate (formData, jqForm, options) {// formdata is an array object. Each object has a name and a value. // The data format is as follows: // [// {name: username, value: usernameValue}, // {name: password, value: passwordValue} //] for (var I = 0; I <formData. length; I ++) {if (! FormData [I]. value) {alert ('user name, address, and self-introduction cannot be blank! '); Return false ;}} var queryString = $. param (formData); // assemble data // alert (queryString); // similar to: name = 1 & add = 2 return true ;}

 

 

4. Detailed code:

 

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 

 

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.