The example in this article describes the method of jquery.form.js to convert form submission into ajax submission. Share it with everyone for your reference. The specific analysis is as follows:
This framework integrates the functions of form submission, verification, and uploading.
This framework must be combined with the full version of jquery, otherwise using min will be invalid.
Principle: Use js to assemble the form into ajax url and data. The principle is still to use ajax to submit. In fact, you can write it yourself, but it may be simpler with this framework.
1. The simplest example:
Step one: quote js
1 2 3 4 |
|
Step 2: Write the form on the page
1 2 3 4 5 6 7 8 9 |
|
Step 3: Write js to call jquery.form.js and submit the form with ajax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
2. What are the values in the options object?
There are several main commonly used attributes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
3. How to parse the json data passed by the server
We know that using the ajax method provided by jquery, if the server passes back json data, it can be converted into a json object of js, and then the corresponding value can be obtained through json.xxx. So what about this framework?
1) First specify dataType in the options parameter: 'json'
2) Submit through the framework
3) Server receives
4) The server returns json
5) Page js receives json
The key is the fifth step. How to receive json via js can be done by performing the following operations inside the method specified by success::
1 2 3 4 5 6 7 8 9 10 |
|
4. How to perform simple verification through this framework?
Speaking of verification, it must be verified inside the beforeSubmit method. How to verify, because this method has passed the jqform object and formData to you. You can use these two parameters to obtain the corresponding input, and then make its own judgment. If the judgment is successful, submit it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Click here for the jquery.form.js fileDownload from this site.
I hope this article will be helpful to everyone’s jQuery programming.