The serialize()
method is a built-in method in jQuery that creates a URL-encoded string by serializing the entire form data or specific form elements.
$(selector).serialize();
This method doesn’t accept any parameters.
This method returns a URL encoded string of the selected element. It will look something like this:
key1=value1&key2=value2...
Let’s look at an example of the serialize()
method in the code snippet below:
In the HTML tab:
jQuery
script.form
.input
element of the text
type.input
element of the number
type.submit
button.In the JavaScript tab:
click()
method on the submit
button.serialize()
method to create a URL-encoded string of form data.serialize()
method is invoked, and the URL-encoded string is printed on the console.