jQuery .serialize() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Ajax Utilities

What You’ll Learn

.serialize() turns live form field values into a URL-encoded query string. This tutorial covers the no-argument signature, successful controls rules, the required name attribute, checkbox and radio behavior, why file inputs are excluded, selecting the <form> vs individual inputs, pairing with $.post() and $.ajax(), comparison with .serializeArray() and $.param(), and common Ajax form patterns.

01

Query String

.serialize()

02

name attr

Required

03

Checked only

Radio/checkbox

04

$.post()

Ajax submit

05

serializeArray

Object array

06

$.param()

Under the hood

Introduction

Ajax form submission usually starts the same way: read every input, build key=value&key2=value2, send it with $.post(). jQuery collapses that into one call — $( "form" ).serialize(). It walks the successful controls in the matched set, reads their current values, URL-encodes them, and returns a single string ready for an Ajax request body or query string.

Under the hood, jQuery gathers name/value pairs (the same data .serializeArray() returns) and passes them through $.param(). That means the encoding rules you learned for param — spaces as +, special characters escaped, array bracket notation — apply here automatically. You focus on the form markup; jQuery handles the string.

Understanding .serialize()

.serialize() is a collection method on jQuery objects containing form elements. It accepts no arguments and returns a String in standard URL-encoded notation. It does not mutate the DOM or submit the form — it only reads values.

Only successful controls are included — the same concept browsers use on native form submit. Every included control must have a name attribute. Unchecked checkboxes and radios are omitted. Disabled fields and file inputs are omitted. Submit button values are never serialized by this method.

💡
Beginner Tip

Select the <form> element — $( "form" ).serialize() — not the form plus all its inputs together. Combining form and children in one jQuery set produces duplicate keys in the output string.

📝 Syntax

Collection method — .serialize()

jQuery
jQuery( formElements ).serialize()

No parameters. Returns a URL-encoded string, or an empty string if no successful controls exist.

Typical Ajax form handler

jQuery
$( "form" ).on( "submit", function( event ) {
  event.preventDefault();
  var query = $( this ).serialize();
  console.log( query );
  // e.g. "username=john&email=john%40example.com"
  $.post( $( this ).attr( "action" ), query );
} );

Equivalence pipeline

jQuery
// These produce the same string for a given form state:
$( "form" ).serialize();

$.param( $( "form" ).serializeArray() );

Successful controls checklist

  • Must have a name attribute — unnamed inputs are skipped.
  • Must not be disabled.
  • Checkboxes / radios — included only when checked.
  • File inputs — never serialized; use FormData for uploads.
  • Submit buttons — not included (form was not submitted via a button).

Return value

  • Returns a String — not a jQuery object. Re-wrap with $() if you need chaining on the form.
  • Empty string when no successful controls are in the set.

⚡ Quick Reference

GoalCode
Serialize entire form$("form").serialize()
Serialize on submit$(this).serialize() inside submit handler
POST via Ajax$.post(url, $("form").serialize())
Debug human-readabledecodeURIComponent($("form").serialize())
Get name/value array instead$("form").serializeArray()
Serialize specific inputs (no form)$("input, select, textarea").serialize()
Live preview on change$("form input, form select").on("change", fn)
File uploadUse FormData — not .serialize()
Avoid duplicatesSelect form only — not form + inputs together

📋 .serialize() vs .serializeArray() vs $.param() vs native submit

Four ways to turn form data into something transmittable — pick based on output format and whether the DOM or a JS object is your source.

.serialize()
form → string

$("form").serialize() — URL-encoded query string from live form controls; ready for $.post()

.serializeArray()
form → array

[{ name, value }, ...] — inspect or transform fields before $.param()

$.param()
object → string

$.param({ a: 1 }) — encode plain objects; .serialize() uses this internally

Native submit
full navigation

<form action method> — browser POST/GET with page reload; no JavaScript required

Use .serialize() for standard Ajax form POST bodies. Use .serializeArray() when you need per-field logic. Use $.param() for non-form data. Use native submit when JavaScript is unavailable and full page navigation is acceptable.

Examples Gallery

Five progressive examples from a basic form serialize through live preview, Ajax POST submission, successful-controls rules, and multiple-select behavior. Each links to a Try-it lab where you can edit and run the code in the browser.

📚 Core Patterns

Read form values into a query string without page reload.

Example 1 — Serialize on submit with preventDefault

Official pattern: intercept form submit, log the serialized string, send via Ajax instead of navigating.

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

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

  $.post( $( this ).attr( "action" ), data, function( response ) {
    console.log( "Server responded", response );
  } );
} );
Try It Yourself

How It Works

$( this ) inside the handler refers to the DOM form element. .serialize() reads only successful controls with name attributes. The returned string is what a native application/x-www-form-urlencoded POST would send.

Example 2 — Live preview on checkbox, radio, and select change

Adapted from the official jQuery demo: call .serialize() whenever controls change and display the string.

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

Each call to .serialize() reflects the current DOM state — useful for debugging forms and building live “preview query string” UI during development.

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

From the jQuery.post() docs — pass serialized form data as the POST body.

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

Because the second argument to $.post() is already a string, jQuery sends it as-is in the POST body. Map your form field name attributes to what your API expects — e.g. title, body, userId for JSONPlaceholder.

📈 Rules & Edge Cases

Understand what gets included and what does not.

Example 4 — Successful controls — name, checked, disabled

Demonstrate official inclusion rules: unnamed fields skipped, unchecked boxes omitted, disabled fields excluded.

jQuery
// Included: named text input, checked checkbox
// Excluded: no name attribute, unchecked radio, disabled field

var str = $( "#demo-form" ).serialize();
$( "#query" ).text( str );

// Typical output when check1 checked, radio2 selected:
// "single=Alpha&check1=on&radio=second&disabled=ignored"
// (disabled field NOT present despite having name)
Try It Yourself

How It Works

These rules mirror native HTML form submission. If a field is missing from your serialized string, check: does it have a name? Is it disabled? For checkboxes/radios, is it checked?

Example 5 — Multiple <select multiple> and duplicate avoidance

Selected options serialize as repeated keys. Select the form element only — not form plus inputs.

jQuery
// Correct — one form, no duplicates
var correct = $( "#tags-form" ).serialize();

// Wrong — form AND inputs → duplicate keys in string
var wrong = $( "#tags-form, #tags-form :input" ).serialize();

$( "#correct" ).text( correct );
// tags=js&tags=jquery&tags=ajax  (multiple selected options)

// Prefer correct selector; compare lengths in Try-it lab
Try It Yourself

How It Works

Multi-select options use repeated name keys — jQuery follows HTML conventions. When a form wraps inputs, selecting only the form is the idiomatic and duplicate-free approach.

🚀 Common Use Cases

  • Ajax form submit — POST serialized data with $.post() instead of full page reload.
  • Filter widgets — serialize a filter form and append to a GET URL or pass to $.get().
  • Debug panel — live-preview the query string while building complex forms.
  • Progressive save — serialize partial forms on blur or timer for auto-save endpoints.
  • Legacy PHP/Rails backends — send standard form-encoded bodies servers already parse.
  • Pair with .load()$.post(url, $("form").serialize()) then update a result region.

🧠 How .serialize() Works Internally

1

Scan matched set

If the set is a <form>, find successful controls inside it. Otherwise serialize controls in the set directly.

controls
2

Filter successful

Keep named, enabled controls. Include checkboxes/radios only if checked. Skip file inputs.

filter
3

Build name/value array

Same step as .serializeArray() — collect { name, value } pairs from each control.

array
4

Pass through $.param()

Encode the array into URL notation — spaces, unicode, and special characters handled.

$.param()
5

Return string

Hand back the query string — pass to $.post(), $.ajax(), or log for debugging.

string
6

Ready for Ajax transport

The string becomes POST body or GET query data — triggers global Ajax events when sent via jQuery shorthands.

📝 Notes

  • .serialize() accepts no arguments and returns a String, not a jQuery object.
  • Every serialized control needs a name attribute — id alone is not enough.
  • Submit button values are never included — the form was not submitted via a button.
  • File inputs are never serialized — use FormData for uploads.
  • Select form only — combining form and inputs duplicates keys.
  • Internally equivalent to $.param( $( form ).serializeArray() ).
  • HTML5 form controls (email, number, date, etc.) serialize like text inputs when successful.
  • For JSON APIs, build a plain object or use JSON.stringify() — not .serialize().

Browser Support

.serialize() is part of jQuery’s core form helpers — not a native DOM API. It works wherever jQuery runs: all browsers supported by your jQuery version, including legacy IE with supported jQuery builds.

jQuery 1.0+

jQuery .serialize() method

Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. HTML5 input types serialize since browsers support them. Successful-control rules follow standard HTML form semantics.

100% With jQuery
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.serialize() Universal

Bottom line: Safe in any jQuery project with forms. Use FormData for file uploads; JSON.stringify for JSON APIs; native FormData/fetch when jQuery is not loaded.

Conclusion

.serialize() is the fastest path from live form fields to an Ajax-ready query string. Remember successful-control rules (name required, checked boxes only, no files), select the <form> element, and pair with $.post() for submit-without-reload patterns.

Continue with the jQuery .serializeArray() tutorial when you need per-field access before encoding, or review the jQuery.param() tutorial for the encoder used under the hood.

💡 Best Practices

✅ Do

  • Give every submittable field a meaningful name attribute
  • Use $( this ).serialize() inside submit handlers on the form
  • Call event.preventDefault() before Ajax POST with serialized data
  • Use .serializeArray() when you need to modify values before sending
  • Validate on the server — serialized strings are easy to forge client-side

❌ Don’t

  • Serialize form and inputs together — duplicates keys in the string
  • Expect file uploads to appear in .serialize() output
  • Rely on submit button values — they are never included
  • Send .serialize() output to JSON-only APIs without server-side parsing
  • Forget disabled fields are silently excluded from the string

Key Takeaways

Knowledge Unlocked

Six things to remember about .serialize()

Form in, query string out.

6
Core concepts
nm 02

name Required

Or field skipped

Markup
ok 03

Successful

Checked/enabled

Rules
fm 04

Select form

Avoid duplicates

Selector
arr 05

serializeArray

{ name, value }

Sibling
pr 06

Uses $.param()

Encoding inside

Internal

❓ Frequently Asked Questions

jQuery .serialize() is a collection method that 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. The string is ready for $.post(), $.ajax() data, or appending to a URL. Returns a String; does not accept arguments.
.serialize() returns one URL-encoded string like a browser would send in application/x-www-form-urlencoded. .serializeArray() returns an array of { name, value } objects — the same structure $.param() accepts. Use .serialize() for Ajax POST bodies and query strings; use .serializeArray() when you need to inspect or transform individual fields in JavaScript before sending.
Only successful controls are included — matching HTML form submission rules. Each control must have a name attribute. Checkboxes and radio buttons are included only when checked. Disabled controls are excluded. File inputs are not serialized. Submit button values are not included unless the form was submitted via that button — .serialize() never includes submit button values.
Select the form element itself: $("form").serialize(). jQuery finds successful controls inside the form. If you select both the form and its children in one set — $("form, :input").serialize() — duplicates appear in the string. You may select individual inputs only when they are not inside a form context.
.serialize() reads live DOM form values and passes them through $.param() internally (via .serializeArray()). Use .serialize() for HTML forms. Use $.param() for plain JavaScript objects or when you already have a name/value array. Both produce URL-encoded strings.
No — file input data is never included in .serialize() output. For file uploads use FormData with $.ajax({ processData: false, contentType: false, data: formData }) instead of .serialize().
Did you know?

.serialize() has existed since jQuery 1.0 — alongside .serializeArray() and the global Ajax helpers. It implements the same successful-control algorithm browsers use on native form submit, which is why unchecked checkboxes vanish from the string. Under the hood it has always delegated encoding to $.param() — so learning param explains why multi-select options appear as repeated keys and why nested field names use bracket notation when you craft inputs manually.

Next: .serializeArray() Method

Get form fields as name/value objects — filter, transform, and build JSON payloads.

.serializeArray() tutorial →

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.

6 people found this page helpful