jQuery .ajaxSuccess() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Ajax

Definition

.ajaxSuccess(handler) is jQuery’s legacy shorthand (since 1.0) for binding a global Ajax “request succeeded” handler on document. It runs only on success — not on error. Internally it is sugar for .on("ajaxSuccess", handler).

Syntax

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

jQuery
// Deprecated (since 3.5)
$(document).ajaxSuccess(function (event, jqXHR, ajaxOptions, data) {
  // runs after every successful qualifying Ajax request
});

// Modern replacement
$(document).on("ajaxSuccess", handler);

// Bind only — no no-arg .ajaxSuccess() trigger form
// Opt out: $.ajax({ url: "/x", global: false })
CallWhat it does
documentOnly valid bind target for global Ajax events
handlerfunction(event, jqXHR, ajaxOptions, data)
ajaxOptions.urlFilter which requests you react to
global: falseSkip all global Ajax events for that call

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

Parameters

ParameterDescription
Step 1Attach the handler to document with .ajaxSuccess(handler) (legacy) or .on("ajaxSuccess", handler) (preferred).
Step 2Make requests with $.ajax(), $.get(), $.post(), or .load().
Step 3Optionally filter with ajaxOptions.url; read jqXHR.responseText or parsed data.

Return Value

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

jQuery Examples

Example 1 — Basic $(document).ajaxSuccess(fn)

Canonical legacy pattern: log when any Ajax request succeeds after a click.

jQuery
$(document).ajaxSuccess(function () {
  $(".log").text("Handler ran via .ajaxSuccess(function(){ ... }).");
});

$("#fetch").on("click", function () {
  $.get("https://jsonplaceholder.typicode.com/posts/1");
});
Try It Yourself

How It Works

  1. Bind. .ajaxSuccess(fn) on document registers a global handler.
  2. Delegate. jQuery routes it to .on("ajaxSuccess", fn) internally.
  3. Click. $.get() starts a qualifying Ajax request.

Example 2 — Filter by settings.url

Handlers run for every success — narrow them with the settings object.

jQuery
var targetUrl = "https://jsonplaceholder.typicode.com/posts/1";

$(document).ajaxSuccess(function (event, xhr, settings) {
  if (settings.url === targetUrl) {
    $(".log").text(
      "URL: " + settings.url + " | responseText: " +
      xhr.responseText.substring(0, 100) + "..."
    );
  }
});
Try It Yourself

How It Works

  1. Args. jQuery passes event, xhr, settings, and data.
  2. Compare. Check settings.url against the endpoint you care about.
  3. Read. Use xhr.responseText for the raw body (or data for parsed).

Example 3 — Append “Successful Request!”

Official-style demo: append a short status string for every successful request.

jQuery
$(document).ajaxSuccess(function (event, request, settings) {
  $("#msg").append(" Successful Request! ");
});
Try It Yourself

How It Works

  1. Global. One handler covers every qualifying successful Ajax call.
  2. Append. Each success adds another status fragment.
  3. Count. Parallel successes each fire their own success event.

Frequently Asked Questions

The .ajaxSuccess(handler) method binds a global function that runs whenever any qualifying jQuery Ajax request completes successfully. Attach it to document: $(document).ajaxSuccess(fn). It is bind-only (no trigger form). Deprecated since jQuery 3.5; use $(document).on("ajaxSuccess", handler) instead.
Yes. $(document).ajaxSuccess(handler) has been deprecated since jQuery 3.5 (available since 1.0). Prefer $(document).on("ajaxSuccess", handler) for new code. Legacy bindings still work in jQuery 3.x; migrate when you touch those files. Remove handlers with $(document).off("ajaxSuccess", handler).
ajaxSuccess is a global Ajax event, not a DOM event on a specific element. Since jQuery 1.9, all global Ajax handlers — including .ajaxSuccess(handler) — must bind to document. Correct legacy form: $(document).ajaxSuccess(fn). Modern form: $(document).on("ajaxSuccess", fn).
Four — the same as the ajaxSuccess event: function(event, jqXHR, ajaxOptions, data). Use jqXHR.responseText for the raw body, data for the processed response, and ajaxOptions.url to identify the request. Failed requests trigger ajaxError instead.
Replace $(document).ajaxSuccess(fn) with $(document).on("ajaxSuccess", fn). Use $(document).off("ajaxSuccess", fn) for cleanup instead of .unbind(). Under the hood, .ajaxSuccess(handler) already delegates to .on("ajaxSuccess") — migration is a straight rename for simple bindings.
Yes. jQuery 3.x keeps .ajaxSuccess(handler) for backward compatibility. It still binds correctly on document. Docs mark it deprecated since 3.5 to steer new projects toward .on(). Prefer the modern API covered in the jQuery ajaxSuccess event tutorial.

Next: ajaxComplete Event

Global handler that runs after every finished request — success or error.

ajaxComplete Event 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.

8 people found this page helpful