jQuery .serialize() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

.serialize() (since jQuery 1.0) encodes successful form controls as a URL-encoded query string — ready for $.post(), $.ajax(), or a GET URL. It takes no arguments and returns a String.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("form").serialize()
// → "name=Jane&email=jane%40example.com"

// Prefer the <form> itself (not form + children)
// Only successful controls (name + checked/enabled rules)
// File inputs are never included
CallWhat it does
Matched setA <form> or form controls to read
name on controlsNameless fields are skipped
ArgumentsMethod takes no parameters
Return valueURL-encoded String

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Give every field you care about a name attribute.
Step 2Select the <form> (or a set of controls) with jQuery.
Step 3Call .serialize() to get a URL-encoded string.

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Serialize on submit

Official pattern: prevent navigation and read the query string.

jQuery
$("#contact-form").on("submit", function (event) {
  event.preventDefault();

  var data = $(this).serialize();
  $("#output").text(data);

  // Optional: $.post($(this).attr("action"), data);
});
Try It Yourself

How It Works

  1. Intercept. The submit handler runs before the browser navigates.
  2. Stop reload. preventDefault() keeps the user on the page.
  3. Serialize. $(this).serialize() reads named successful controls.

Example 2 — Live Preview on Change

Adapted from the jQuery docs demo: update the string as controls change.

jQuery
function showValues() {
  var str = $("form").serialize();
  $("#results").text(str || "(empty — no successful controls)");
}

$("input[type='checkbox'], input[type='radio']").on("click", showValues);
$("select").on("change", showValues);
$("input[type='text']").on("input", showValues);

showValues();
Try It Yourself

How It Works

  1. Bind. Listen for click / change / input on controls.
  2. Read. Each event calls $("form").serialize() again.
  3. Reflect. The string always matches the current DOM state.

Example 3 — $.post(url, $form.serialize())

Pass the serialized string as the POST body — common Ajax form pattern.

jQuery
$("#save-form").on("submit", function (event) {
  event.preventDefault();
  var $form = $(this);

  $.post(
    $form.attr("action"),
    $form.serialize(),
    function (data) {
      $("#status").text("Saved! Server id: " + data.id);
    },
    "json"
  );
});
Try It Yourself

How It Works

  1. Build string. .serialize() creates form-urlencoded data.
  2. POST. The second argument to $.post() is that string.
  3. Send as-is. jQuery posts it as the request body.

Frequently Asked Questions

jQuery .serialize() encodes successful form controls in the matched set as a URL-encoded query string (for example "name=John&email=john%40example.com"). Call $("form").serialize() to read current field values without a full page submit. Returns a String and takes no arguments.
.serialize() returns one URL-encoded string. .serializeArray() returns an array of { name, value } objects. Use .serialize() for Ajax POST bodies and query strings; use .serializeArray() when you need to inspect or transform fields in JavaScript first.
Only successful controls are included — matching HTML form submission rules. Each control needs a name attribute. Checkboxes and radios are included only when checked. Disabled controls and file inputs are excluded. Submit button values are not included by .serialize().
Prefer selecting the form: $("form").serialize(). jQuery finds successful controls inside it. Selecting both the form and its children in one set causes duplicate keys in the string.
.serialize() reads live DOM values (via .serializeArray()) and builds a string with $.param() under the hood. Use .serialize() for HTML forms; use $.param() for plain objects or name/value arrays you already have.
No. File input data is never included. For uploads use FormData with $.ajax({ processData: false, contentType: false, data: formData }).

Next: .serializeArray() Method

Get an array of name/value objects you can inspect or transform before sending.

.serializeArray() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful