Encode a set of form elements as a string for submission
From the jQuery API documentation:
The
.serialize()
method creates a text string in standard URL-encoded notation. It can act on ajQuery
object that has selected individualform controls
, such as<input>
,<textarea>
, and<select>
:$( "input, textarea, select" ).serialize();
It is typically easier, however, to select the
<form>
itself for serialization:$( "form" ).on( "submit", function( event ) { event.preventDefault(); console.log( $( this ).serialize() ); });
In this case,
jQuery
serializes the successful controls within the form. Onlyform elements
are examined for inputs they contain, in all other cases the input elements to be serialized should be part of the set passed to the.serialize()
method. Selecting both the form and its children in a set will cause duplicates in the serialized string.