Jquery Ajax-serialize () method
Jquery Ajax Reference Manual
Instance
Output serialized form value results:
$("button").click(function(){ $("div").text($("form").serialize());});
Try it yourself
Definition and usage
The serialize () method creates a URL encoded text string by serializing the form value.
You can select one or more form elements (such as input and/or text boxes) or Form elements.
Serialized values can be used in URL query strings when an Ajax request is generated.
Syntax
$(selector).serialize()
Detailed description
The. serialize () method creates a text string encoded with a standard URL. Its operation object is a jquery object that represents the form Element Set.
There are several types of form elements:
<form> <div><input type="text" name="a" value="1" id="a" /></div> <div><input type="text" name="b" value="2" id="b" /></div> <div><input type="hidden" name="c" value="3" id="c" /></div> <div> <textarea name="d" rows="8" cols="40">4</textarea> </div> <div><select name="e"> <option value="5" selected="selected">5</option> <option value="6">6</option> <option value="7">7</option> </select></div> <div> <input type="checkbox" name="f" value="8" id="f" /> </div> <div> <input type="submit" name="g" value="Submit" id="g" /> </div></form>
The. serialize () method can operate jquery objects that have selected individual form elements, such as <input>, <textarea>, and <SELECT>. However, it is easier to select the <form> label itself for serialization:
$('form').submit(function() { alert($(this).serialize()); return false;});
Output standard query string:
a=1&b=2&c=3&d=4&e=5
Note: Only "successful controls" are serialized as strings. If the button is not used to submit a form, the value of the submit button is not serialized. To include the value of a form element in a sequence string, the element must use the name attribute.
Jquery Ajax Reference Manual