.serialize()
S2C Home « Ajax « .serialize()
Form element string encryption.
Description
The .serialize()
Ajax method, allows us to encode a set of form elements as a string ready for submission.
- The
.serialize()
method returns a text string in standard URL-encoded notation and operates on a jQuery object representing a set of form elements. - The
.serialize()
method can act on a jQuery object that has form elements of several types if required, although it is generally easier to select the <form> element. - Only 'successful controls' are serialized to the returned string as outlined in the
W3C Proposals
.
Syntax
Signature | Description |
---|---|
.serialize() | Encode a set of form elements as a string ready for submission. |
Parameters
None.
Return
A String
object.
.serialize()
ExampleTop
Encode a set of form elements as a string ready for submission.
In the example below when we press the 'Submit' button the we serialize the 'successful controls' from the form below into a query string. For the example we output a message but the resultant string could just as easily be sent to a server as part of an Ajax request. Change some values in the form and press the 'Submit' button to see the varying results.
$(function(){
$('#form1').submit(function() {
$('#div1').append($(this).serialize() + '<br>');
return false;
});
;});
div1. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 10 - Ajax Helper Functions