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

progressCallbacks notification.

Description

The deferred.notify() Deferred method, calls any progressCallbacks on a Deferred object, optionally passing 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.notify method is called, any progressCallbacks added by the deferred.then() or deferred.progress() methods are called.
  • Callbacks are executed in the order they were added and each callback is passed the args from the deferred.notify method if any were specified.
  • Any calls to the deferred.notify after a Deferred object is resolved or rejected, as well as any progressCallbacks added after this change of state, are ignored.

Syntax

Signature Description
deferred.notify( [args] )Call any progressCallbacks on a Deferred object, optionally passing arguments.

Parameters

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

Return

A Deferred object.

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

Call any progressCallbacks on a Deferred object, optionally passing 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 notify the Deferred object with no arguments and process any progressCallbacks before resolving 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 notify the Deferred object with some arguments and process any progressCallbacks before rejecting it.


$(function(){
  $('#btn7').one('click', function(){
    var ourDeferred = $.Deferred();
    ourDeferred.done( eFunc );
    ourDeferred.fail( eFunc );
    ourDeferred.progress( fFunc );
    ourDeferred.notify();
    ourDeferred.resolve( 'Our deferred was resolved. <br><br>', '#div1' );
  });
  $('#btn8').one('click', function(){
    var ourDeferred = $.Deferred();
    ourDeferred.done( eFunc );
    ourDeferred.fail( eFunc );
    ourDeferred.progress( eFunc );
    ourDeferred.notify( 'function was fired from our deferred. <br>', '#div1');
    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>');
  }
});

div1. Some initial text.

Press the button below to action the above code:

               

Related Tutorials

jQuery Advanced Tutorials - Lesson 7 - The Deferred Object