jQuery .post() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

jQuery.post(url [, data] [, success] [, dataType]) sends an HTTP POST request (since 1.0). It is shorthand for $.ajax({ type: "POST", … }). Data goes in the request body — not the URL.

Syntax

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

jQuery
$.post("ajax/test.html", function (data) {
  $(".result").html(data);
});

// Equivalent to:
$.ajax({
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

// POST responses are never cached
CallWhat it does
jQueryLearn jQuery.post(): POST shorthand for $.ajax(), url/data/success/dataType, form serialize(), jqXHR done/fail/always, never-cached POSTs, silent errors, and compare with $.get().

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

Parameters

ParameterDescription
Step 1Call $.post(url) or pass a data object/string for the body.
Step 2Add a success callback, or chain .done() on the returned jqXHR.
Step 3Optionally set dataType (e.g. "json") as the fourth argument.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — POST with Data + Success

Official pattern: send a payload and handle the response.

jQuery
$.post("test.php", { name: "John", time: "2pm" })
  .done(function (data) {
    alert("Data Loaded: " + data);
  });

// Live demo style:
$.post("https://jsonplaceholder.typicode.com/posts", {
  title: "My new post",
  body: "Created with $.post()",
  userId: 1
}, function (data, textStatus, jqXHR) {
  $("#result").text("Created post #" + data.id + " (" + textStatus + ")");
});
Try It Yourself

How It Works

  1. Body. The data object is serialized with $.param() into the POST body.
  2. Send. jQuery issues an HTTP POST (never cached).
  3. Success. The callback receives (data, textStatus, jqXHR).

Example 2 — Fourth Argument "json"

Tell jQuery to parse the response as JSON before your callback runs.

jQuery
$.post("test.php", { func: "getNameAndTime" }, function (data) {
  console.log(data.name); // John
  console.log(data.time); // 2pm
}, "json");
Try It Yourself

How It Works

  1. Hint. The fourth argument sets expected dataType.
  2. Parse. jQuery converts the body to a JavaScript object.
  3. Callback. You read properties like data.name directly.

Example 3 — POST Serialized Form Data

Official pattern: pass $("#form").serialize() as the body.

jQuery
$.post("test.php", $("#testform").serialize());

// With feedback:
var payload = $("#contact-form").serialize();
$.post("https://jsonplaceholder.typicode.com/posts", payload, function (data) {
  $("#status").text("Saved! id=" + data.id);
}, "json");
Try It Yourself

How It Works

  1. Read. .serialize() builds a URL-encoded string from named fields.
  2. Send. Pass the string as data — jQuery does not re-encode strings.
  3. POST. The string becomes the request body.

Frequently Asked Questions

jQuery.post() is a shorthand for $.ajax() configured as a POST request. Pass a URL, optional data, optional success callback, and optional dataType. Since jQuery 1.12 you can also pass a settings object: $.post({ url, data, dataType }). It returns a jqXHR object.
Both share the same positional signature, but $.post() sets type to POST so data goes in the request body (application/x-www-form-urlencoded by default), while $.get() appends data to the URL. Use $.get() for reads and $.post() for writes and form submissions.
A jqXHR object — a Promise-like wrapper around XMLHttpRequest. Chain .done(fn) for success, .fail(fn) for errors, and .always(fn) for either outcome. Handlers can be attached after completion; if the request already finished, the callback fires immediately.
No. Pages fetched with POST are never cached. The cache and ifModified options in $.ajaxSetup() have no effect on $.post() requests.
Yes — unless you chain .fail() on the returned jqXHR or register a global ajaxError handler, errors do not surface. The success callback simply never runs. Always chain .fail() when users need feedback.
Use $.post() for simple POSTs. Use $.ajax() for full control: custom headers, contentType application/json, beforeSend, processData false for FormData, global false, or other settings not exposed as positional arguments.

Next: jQuery.getJSON() Method

Fetch JSON with a dedicated GET shorthand.

jQuery.getJSON() 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.

9 people found this page helpful