jQuery Deferred reject() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Settle as failed

What You’ll Learn

The reject() method marks a jQuery Deferred as failed. It runs fail() and catch() handlers with your error reason — and prevents done() from firing. This tutorial covers syntax, five examples, comparisons with resolve() and fail(), and when to reject vs resolve.

01

Syntax

dfd.reject(reason)

02

State

rejected

03

fail()

Handlers run

04

vs resolve

One settlement

05

Owner only

Not on promise

06

Since 1.5

Core Deferred API

Introduction

Not every async task succeeds. Validation can fail, networks time out, and servers return errors. When you own a $.Deferred(), you signal failure by calling reject() — the mirror image of resolve() for success.

Listeners registered with fail() or catch() receive the rejection reason. Consumers holding only a promise() cannot call reject() — only the module that created the Deferred settles it.

Understanding the reject() Method

reject() transitions a pending Deferred into the rejected state. jQuery invokes every queued fail(), catch(), and always() handler with the arguments you pass to reject().

Once rejected, the state is permanent — you cannot resolve() the same Deferred afterward. done() handlers never run on a rejected Deferred.

💡
Beginner Tip

Register fail() before calling reject() if handlers must run synchronously in the same turn — same rule as done() before resolve(). The reference example attaches handlers first, then rejects inside setTimeout, which is correct.

📝 Syntax

General form of deferred.reject:

jQuery
deferred.reject( [ args ] )

Parameters

  • args (optional) — rejection reason(s) forwarded to fail() handlers: string, Error, object, or multiple values.

Return value

  • Returns the same Deferred object for chaining (though state is now locked to rejected).

Basic reject + fail handler

jQuery
const dfd = $.Deferred();

dfd.fail(function (error) {
  console.error("Error:", error);
});

dfd.reject("Operation failed: invalid input");

⚡ Quick Reference

GoalCode
Mark as faileddfd.reject(reason)
Listen for failuredfd.fail(fn)
Mark as successdfd.resolve(value)
Either outcome cleanupdfd.always(fn)
Reject with custom thisdfd.rejectWith(ctx, [reason])

📋 reject() vs fail() vs resolve()

Settle failure, listen for failure, or settle success — three distinct roles.

reject()
settle fail

Owner signals error

fail()
listen

Callback on reject

resolve()
settle OK

Opposite outcome

Once
locked

One settlement only

Examples Gallery

Each example shows when and how to call reject(). Use the Try-it links to run them interactively.

📚 Getting Started

Reject with an error message and handle it in fail().

Example 1 — Basic Rejection

Call reject() with a string; fail() logs the error.

jQuery
const dfd = $.Deferred();

dfd.fail(function (error) {
  console.error("Error:", error);
});

dfd.reject("Network timeout");
Try It Yourself

How It Works

reject() settles immediately. Every registered fail() handler runs with "Network timeout".

Example 2 — Conditional Reject (Async Check)

After async work, reject when a condition fails — like the reference example.

jQuery
const dfd = $.Deferred();

dfd.done(function (message) {
  console.log("Success:", message);
}).fail(function (error) {
  console.error("Error:", error);
});

setTimeout(function () {
  const conditionMet = false;

  if (conditionMet) {
    dfd.resolve("Operation completed successfully.");
  } else {
    dfd.reject("Operation failed: Condition not met.");
  }
}, 500);
Try It Yourself

How It Works

Handlers attach first; the timer decides resolve or reject. Only one path runs — failure skips done() entirely.

📈 Practical Patterns

Mutual exclusion with resolve, rich error payloads, and encapsulated APIs.

Example 3 — reject() vs resolve()

A Deferred settles once — success and failure are mutually exclusive.

jQuery
function settle(ok) {
  const dfd = $.Deferred();

  dfd.done(function (v) { console.log("resolved:", v); });
  dfd.fail(function (e) { console.log("rejected:", e); });

  if (ok) {
    dfd.resolve("OK");
    dfd.reject("Too late");  // ignored — already resolved
  } else {
    dfd.reject("Failed");
    dfd.resolve("Too late"); // ignored — already rejected
  }
}

settle(false);  // rejected: Failed
Try It Yourself

How It Works

The second settlement call is ignored. Always pick exactly one: resolve() or reject().

Example 4 — Multiple Rejection Arguments

Pass status, message, and code — fail() receives them as separate parameters.

jQuery
const dfd = $.Deferred();

dfd.fail(function (status, message, code) {
  console.log(status, message, "(" + code + ")");
});

dfd.reject(404, "Not found", "ERR_404");
Try It Yourself

How It Works

Same multi-argument pattern as resolve() — useful for HTTP-style error tuples in custom async helpers.

Example 5 — Reject Inside a promise() API

Module rejects internally; callers handle failure on the returned promise.

jQuery
function saveUser(name) {
  const dfd = $.Deferred();

  if (!name || name.length < 2) {
    dfd.reject("Name must be at least 2 characters");
  } else {
    dfd.resolve({ saved: true, name: name });
  }

  return dfd.promise();
}

saveUser("A").catch(function (err) {
  console.error("Save failed:", err);
});
Try It Yourself

How It Works

Validation rejects early; external code only sees the read-only promise and uses catch() for errors.

🚀 Use Cases

  • Input validation — reject when form data fails checks before sending to the server.
  • Failed AJAX — wrap XHR errors and call reject() in custom Deferred-based helpers.
  • Aborted operations — reject when the user cancels a long task.
  • Business rule failures — reject when server logic returns an error payload you treat as failure.
  • Promise chains — reject propagates to downstream fail() / catch() handlers.

🧠 What Happens When You Call reject()

1

Pending

Deferred waits; fail() handlers may already be registered.

Before
2

reject()

State locks to rejected; fail/catch/always handlers run.

Settle
3

No done()

Success handlers are skipped; further resolve/reject calls ignored.

Final
=

Handled failure

User sees error UI via fail(); cleanup via always().

📝 Notes

  • Only call reject() on Deferreds you own — not on promises returned to you.
  • Always pair public async APIs with consumer-side fail() or catch().
  • Use descriptive rejection reasons — strings, Error objects, or structured data.
  • state() returns "rejected" after reject (preferred over deprecated isRejected() in jQuery 3+).
  • For custom this in fail handlers, use rejectWith() next.

Browser Support

deferred.reject() has been available since jQuery 1.5 alongside the Deferred API. It works in jQuery 1.5+, 2.x, and 3.x.

jQuery 1.5+

jQuery Deferred.reject()

Universal wherever jQuery Deferred runs. jqXHR uses the same rejection machinery when AJAX requests fail.

100% With jQuery loaded
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
deferred.reject() Universal

Bottom line: Core API for signaling async failure in jQuery since 1.5. Always handle rejections on the consumer side.

🎉 Conclusion

The deferred.reject() method settles a Deferred as failed. Call it when validation fails, networks error, or business rules block success — then let fail() and catch() inform the user.

Next, explore rejectWith() when fail handlers need a custom this context, or review resolve() for the success counterpart.

💡 Best Practices

✅ Do

  • Register fail() before or when returning promises
  • Pass clear, actionable rejection messages
  • Reject early on validation failures
  • Use always() for shared cleanup
  • Return promise() — reject on the private Deferred

❌ Don’t

  • Call both resolve() and reject()
  • Reject without any fail/catch handler in user flows
  • Expose reject() on public promise objects
  • Swallow errors silently after reject
  • Assume done() runs after reject

Key Takeaways

Knowledge Unlocked

Five things to remember about reject()

How to signal failure on a jQuery Deferred.

5
Core concepts
02

State

rejected

Failed
fail 03

fail()

Runs on reject

Listen
1x 04

Once

Locked state

Final
vs 05

resolve

Opposite

Pair

❓ Frequently Asked Questions

reject() settles the Deferred as failed. It triggers fail(), catch(), and the rejection branch of always() handlers, passing optional rejection values (error message, object, etc.). The state locks to rejected — done() will not run.
reject() is called by the Deferred owner to signal failure. fail() registers a callback that runs when rejection happens. Think: reject() fires the event; fail() listens for it.
No. A Deferred settles once. If it already resolved, a later reject() is ignored. Likewise, resolve() after reject() has no effect.
Any value — a string message, Error object, HTTP status, or multiple arguments like reject(status, body, xhr). fail() handlers receive the same arguments.
No. Rejection triggers fail/catch/always, not progress. Send final progress updates before reject() if needed.
Use rejectWith(context, args) when fail() handlers need a specific this value and arguments in an array — same pattern as resolveWith() and notifyWith().
Did you know?

When a jQuery AJAX request fails, the jqXHR object rejects its internal Deferred automatically — you handle it with .fail() without calling reject() yourself. Custom helpers that wrap non-jQuery async code use reject() the same way jQuery does internally for HTTP errors.

Continue to rejectWith()

Learn how to reject with a custom this context in fail handlers.

rejectWith() 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