.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
Fundamentals
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.
Concept
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.
Foundation
📝 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 bedisabled.
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.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Serialize entire form
$("form").serialize()
Serialize on submit
$(this).serialize() inside submit handler
POST via Ajax
$.post(url, $("form").serialize())
Debug human-readable
decodeURIComponent($("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 upload
Use FormData — not .serialize()
Avoid duplicates
Select form only — not form + inputs together
Compare
📋 .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()
<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.
Hands-On
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 );
} );
} );
User submits form → preventDefault stops navigation
#output shows "name=Jane&email=jane%40example.com&message=Hello"
$.post sends same string as request body
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.
Toggle checkbox → string updates instantly in #results
Uncheck radio/checkbox → that name drops from string
Change select → new option value appears encoded
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"
);
} );
serialize() → "title=My+Post&body=Content&userId=1"
$.post POSTs that string as body (not query string)
Success callback receives parsed JSON response
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
// 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)
Input without name → never appears in string
Unchecked checkbox → omitted until checked
Disabled input → always omitted
File input → never serialized
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
Multiple select with 3 options chosen:
tags=js&tags=jquery&tags=ajax
Form + children selector → each field appears twice (bug)
Always serialize $( "form" ) or $( this ) in submit handler
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.
Applications
🚀 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.
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.
Important
📝 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().
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about .serialize()
Form in, query string out.
6
Core concepts
str01
URL String
Ready for $.post()
Output
nm02
name Required
Or field skipped
Markup
ok03
Successful
Checked/enabled
Rules
fm04
Select form
Avoid duplicates
Selector
arr05
serializeArray
{ name, value }
Sibling
pr06
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.