The serialize () method is also an object that acts on a jquery when more form elements are submitted, and it is able to serialize the contents of the DOM elements into strings for Ajax requests.
The serialize () method creates a URL-encoded text string by serializing the form value.
The. Serialize () method can manipulate JQuery objects that have selected individual form elements, such as <input> <textarea> and <select>. However, it is generally easier to select the <form> tag itself for serialization:
$ (' form '). Submit (function () { alert (this). Serialize ()); return false;});
Output a standard query string:
A=1&b=2&c=3&d=4&e=5
Note: Only successful controls are serialized as strings. If you do not use a button to submit the form, the value of the Submit button is not serialized. If the value of the form element is to be included in the sequence string, the element must use the Name property.
The two parts of the graph are equivalent relations
Serializearray () method
The Serializearray () method is similar to the Serialize () method, which returns a JSON-formatted string after serializing the DOM element instead of returning a string.
Note: This method returns a JSON object rather than a JSON string. You need to use a plug-in or a third-party library for string manipulation.
The returned JSON object consists of an array of objects, each of which contains one or two name-value pairs of the--name parameter and the value parameter if value is not empty. For example:
12 {name: ' FirstName ', Value: ' Hello '3 {name: ' LastName ', Value: ' World '},4 // value is empty 5 ]
The. Serializearray () method uses the standard of the successful controls (active control) to detect which elements should be included. Specifically, the element cannot be disabled (disabled elements are not included), and the element should have a name attribute. The value of the Submit button is also not serialized. The data for the file selection element is also not serialized.
This method can operate on objects that have selected individual form elements, such as <input>, <textarea>, and <select>. However, a more convenient way is to directly select the <form> tag itself for the serialization operation.
Param () method
The Param () method is the core of the Serialize () method, which is used to serialize an array and an object according to Key/value
For example, to serialize an ordinary object:
var obj={a:1,b:2,c:3}; var k = $.param (obj); alert (k); // Output a=1&b=2&c=3
jquery serialization Element Serialize () method Serializearray () method param () method