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 itbeforeSubmit
Callback 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">