deferred.reject() JQ Home  <<  Objects  <<  deferred.reject()

failCallbacks rejection.

Description

The deferred.reject() Deferred method, rejects a Deferred object and calls any failCallbacks with the specified arguments.

  • Only the creator of a Deferred object should call this method. Other code can be stopped from changing Deferred object state or from reporting Deferred object status by returning a restricted Promise object through the deferred.promise() method.
  • When the deferred.reject method is called, any progressCallbacks added by the deferred.then() or deferred.fail() methods are called.
  • Callbacks are executed in the order they were added and each callback is passed the args from the deferred.reject method if any were specified.
  • Any failCallbacks added after the Deferred object enters the rejected state are executed immediately when they are added, using the arguments that were passed to the deferred.reject method.

Syntax

Signature Description
deferred.reject( [args] )Reject a Deferred object and call any failCallbacks with the specified arguments.

Parameters

Parameter Description Type
args Arguments that are passed to the failCallbacks.Object

Return

A Deferred object.

deferred.reject( [args] ) ExamplesObjects  <<  Top

Reject a Deferred object and call any failCallbacks with the specified arguments.

In the example below when we press the left button the first time we create a Deferred object and use some deferred object methods on it. We then reject the Deferred object with no arguments and process any failCallbacks before rejecting it.

When we press the right button the first time we create a Deferred object and use some deferred object methods on it. We then reject the Deferred object with some arguments and process any failCallbacks before rejecting it.


$(function(){
  $('#btn9').one('click', function(){
    var ourDeferred = $.Deferred();
    ourDeferred.fail( fFunc );
    ourDeferred.reject();
  });
  $('#btn10').one('click', function(){
    var ourDeferred = $.Deferred();
    ourDeferred.fail( eFunc );
    ourDeferred.reject( 'Our deferred was rejected. <br><br>', '#div1' );
  });

  function eFunc( value, div ){
    $(div).append( 'In eFunc: ' + value);
  }
  function fFunc(){
    $('#div1').append( 'In fFunc: with no args. <br><br>');
  }
});

div1. Some initial text.

Press the button below to action the above code:

               

Related Tutorials

jQuery Advanced Tutorials - Lesson 7 - The Deferred Object