Options
All
  • Public
  • Public/Protected
  • All
Menu

Type Parameters

  • TR

  • TJ = any

  • TN = any

Hierarchy

  • Deferred

Index

Methods

  • Add handlers to be called when the Deferred object is either resolved or rejected.

    see

    ``

    since

    1.6

    example

    ​ ````Since the jQuery.get() method returns a jqXHR object, which is derived from a Deferred object, we can attach a callback for both success and error using the deferred.always() method.

    $.get( "test.php" ).always(function() {
    alert( "$.get completed with success or error callback arguments" );
    });

    Parameters

    • alwaysCallback: TypeOrArray<Callback<TR | TJ>>

      A function, or array of functions, that is called when the Deferred is resolved or rejected.

    • Rest ...alwaysCallbacks: TypeOrArray<Callback<TR | TJ>>[]

      Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected.

    Returns Deferred<TR, TJ, TN>

  • catch<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>(failFilter?: null | ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>)): PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>
  • Add handlers to be called when the Deferred object is rejected.

    see

    ``

    since

    3.0

    example

    ​ ````Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can rejection handlers using the .catch method.

    $.get( "test.php" )
    .then( function() {
    alert( "$.get succeeded" );
    } )
    .catch( function() {
    alert( "$.get failed!" );
    } );

    Type Parameters

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    Parameters

    • Optional failFilter: null | ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>)

      A function that is called when the Deferred is rejected.

    Returns PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>

  • Add handlers to be called when the Deferred object is resolved.

    see

    ``

    since

    1.5

    example

    ​ ````Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can attach a success callback using the .done() method.

    $.get( "test.php" ).done(function() {
    alert( "$.get succeeded" );
    });
    example

    ​ ````Resolve a Deferred object when the user clicks a button, triggering a number of callback functions:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>deferred.done demo</title>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    </head>
    <body>

    <button>Go</button>
    <p>Ready...</p>

    <script>
    // 3 functions to call when the Deferred object is resolved
    function fn1() {
    $( "p" ).append( " 1 " );
    }
    function fn2() {
    $( "p" ).append( " 2 " );
    }
    function fn3( n ) {
    $( "p" ).append( n + " 3 " + n );
    }

    // Create a deferred object
    var dfd = $.Deferred();

    // Add handlers to be called when dfd is resolved
    dfd
    // .done() can take any number of functions or arrays of functions
    .done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
    // We can chain done methods, too
    .done(function( n ) {
    $( "p" ).append( n + " we're done." );
    });

    // Resolve the Deferred object when the button is clicked
    $( "button" ).on( "click", function() {
    dfd.resolve( "and" );
    });
    </script>

    </body>
    </html>

    Parameters

    • doneCallback: TypeOrArray<Callback<TR>>

      A function, or array of functions, that are called when the Deferred is resolved.

    • Rest ...doneCallbacks: TypeOrArray<Callback<TR>>[]

      Optional additional functions, or arrays of functions, that are called when the Deferred is resolved.

    Returns Deferred<TR, TJ, TN>

  • Add handlers to be called when the Deferred object is rejected.

    see

    ``

    since

    1.5

    example

    ​ ````Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred, you can attach a success and failure callback using the deferred.done() and deferred.fail() methods.

    $.get( "test.php" )
    .done(function() {
    alert( "$.get succeeded" );
    })
    .fail(function() {
    alert( "$.get failed!" );
    });

    Parameters

    • failCallback: TypeOrArray<Callback<TJ>>

      A function, or array of functions, that are called when the Deferred is rejected.

    • Rest ...failCallbacks: TypeOrArray<Callback<TJ>>[]

      Optional additional functions, or arrays of functions, that are called when the Deferred is rejected.

    Returns Deferred<TR, TJ, TN>

  • notify(...args: TN[]): Deferred<TR, TJ, TN>
  • Call the progressCallbacks on a Deferred object with the given args.

    see

    ``

    since

    1.7

    Parameters

    • Rest ...args: TN[]

      Optional arguments that are passed to the progressCallbacks.

    Returns Deferred<TR, TJ, TN>

  • notifyWith(context: object, args?: ArrayLike<TN>): Deferred<TR, TJ, TN>
  • Call the progressCallbacks on a Deferred object with the given context and args.

    see

    ``

    since

    1.7

    Parameters

    • context: object

      Context passed to the progressCallbacks as the this object.

    • Optional args: ArrayLike<TN>

      An optional array of arguments that are passed to the progressCallbacks.

    Returns Deferred<TR, TJ, TN>

  • pipe<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND, ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF, ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>), progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARD | ARF | ARP, AJD | AJF | AJP, AND | ANF | ANP, BRD | BRF | BRP, BJD | BJF | BJP, BND | BNF | BNP, CRD | CRF | CRP, CJD | CJF | CJP, CND | CNF | CNP, RRD | RRF | RRP, RJD | RJF | RJP, RND | RNF | RNP>
  • pipe<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF, ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: null, failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>), progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARF | ARP, AJF | AJP, ANF | ANP, BRF | BRP, BJF | BJP, BNF | BNP, CRF | CRP, CJF | CJP, CNF | CNP, RRF | RRP, RJF | RJP, RNF | RNP>
  • pipe<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND, ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter: null, progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARD | ARP, AJD | AJP, AND | ANP, BRD | BRP, BJD | BJP, BND | BNP, CRD | CRP, CJD | CJP, CND | CNP, RRD | RRP, RJD | RJP, RND | RNP>
  • pipe<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: null, failFilter: null, progressFilter?: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>
  • pipe<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND, ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>), progressFilter?: null): PromiseBase<ARD | ARF, AJD | AJF, AND | ANF, BRD | BRF, BJD | BJF, BND | BNF, CRD | CRF, CJD | CJF, CND | CNF, RRD | RRF, RJD | RJF, RND | RNF>
  • pipe<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>(doneFilter: null, failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>), progressFilter?: null): PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>
  • pipe<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter?: null, progressFilter?: null): PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND>
  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Filter resolve value:

    var defer = $.Deferred(),
    filtered = defer.pipe(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    alert( "Value is ( 2*5 = ) 10: " + value );
    });
    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.pipe( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      An optional function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>
        • Parameters

          • Rest ...t: TJ[]

          Returns AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>

    • progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARD | ARF | ARP, AJD | AJF | AJP, AND | ANF | ANP, BRD | BRF | BRP, BJD | BJF | BJP, BND | BNF | BNP, CRD | CRF | CRP, CJD | CJF | CJP, CND | CNF | CNP, RRD | RRF | RRP, RJD | RJF | RJP, RND | RNF | RNP>

  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.pipe( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: null

      An optional function that is called when the Deferred is resolved.

    • failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>
        • Parameters

          • Rest ...t: TJ[]

          Returns AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>

    • progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARF | ARP, AJF | AJP, ANF | ANP, BRF | BRP, BJF | BJP, BNF | BNP, CRF | CRP, CJF | CJP, CNF | CNP, RRF | RRP, RJF | RJP, RNF | RNP>

  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Filter resolve value:

    var defer = $.Deferred(),
    filtered = defer.pipe(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    alert( "Value is ( 2*5 = ) 10: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      An optional function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • failFilter: null

      An optional function that is called when the Deferred is rejected.

    • progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARD | ARP, AJD | AJP, AND | ANP, BRD | BRP, BJD | BJP, BND | BNP, CRD | CRP, CJD | CJP, CND | CNP, RRD | RRP, RJD | RJP, RND | RNP>

  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: null

      An optional function that is called when the Deferred is resolved.

    • failFilter: null

      An optional function that is called when the Deferred is rejected.

    • Optional progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>

  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Filter resolve value:

    var defer = $.Deferred(),
    filtered = defer.pipe(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    alert( "Value is ( 2*5 = ) 10: " + value );
    });
    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.pipe( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      An optional function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>
        • Parameters

          • Rest ...t: TJ[]

          Returns AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>

    • Optional progressFilter: null

      An optional function that is called when progress notifications are sent to the Deferred.

    Returns PromiseBase<ARD | ARF, AJD | AJF, AND | ANF, BRD | BRF, BJD | BJF, BND | BNF, CRD | CRF, CJD | CJF, CND | CNF, RRD | RRF, RJD | RJF, RND | RNF>

  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.pipe( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    Parameters

    • doneFilter: null

      An optional function that is called when the Deferred is resolved.

    • failFilter: ((...t: TJ[]) => AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>
        • Parameters

          • Rest ...t: TJ[]

          Returns AJF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<AJF>

    • Optional progressFilter: null

      An optional function that is called when progress notifications are sent to the Deferred.

    Returns PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>

  • Utility method to filter and/or chain Deferreds.

    see

    ``

    since

    1.6

    since

    1.7

    deprecated

    ​ Deprecated since 1.8. Use ``.

    Cause: The .pipe() method on a jQuery.Deferred object was deprecated as of jQuery 1.8, when the .then() method was changed to perform the same function.

    Solution: In most cases it is sufficient to change all occurrences of .pipe() to .then(). Ensure that you aren't relying on context/state propagation (e.g., using this) or synchronous callback invocation, which were dropped from .then() for Promises/A+ interoperability as of jQuery 3.0.

    example

    ​ ````Filter resolve value:

    var defer = $.Deferred(),
    filtered = defer.pipe(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    alert( "Value is ( 2*5 = ) 10: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.pipe(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      An optional function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • Optional failFilter: null

      An optional function that is called when the Deferred is rejected.

    • Optional progressFilter: null

      An optional function that is called when progress notifications are sent to the Deferred.

    Returns PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND>

  • Add handlers to be called when the Deferred object generates progress notifications.

    see

    ``

    since

    1.7

    Parameters

    • progressCallback: TypeOrArray<Callback<TN>>

      A function, or array of functions, to be called when the Deferred generates progress notifications.

    • Rest ...progressCallbacks: TypeOrArray<Callback<TN>>[]

      Optional additional functions, or arrays of functions, to be called when the Deferred generates progress notifications.

    Returns Deferred<TR, TJ, TN>

  • promise<TTarget>(target: TTarget): Promise<TR, TJ, TN> & TTarget
  • promise(): Promise<TR, TJ, TN>
  • Return a Deferred's Promise object.

    see

    ``

    since

    1.5

    example

    ​ ````Use the target argument to promote an existing object to a Promise:

    // Existing object
    var obj = {
    hello: function( name ) {
    alert( "Hello " + name );
    }
    },
    // Create a Deferred
    defer = $.Deferred();

    // Set object as a promise
    defer.promise( obj );

    // Resolve the deferred
    defer.resolve( "John" );

    // Use the object as a Promise
    obj.done(function( name ) {
    obj.hello( name ); // Will alert "Hello John"
    }).hello( "Karl" ); // Will alert "Hello Karl"

    Type Parameters

    • TTarget extends object

    Parameters

    • target: TTarget

      Object onto which the promise methods have to be attached

    Returns Promise<TR, TJ, TN> & TTarget

  • Return a Deferred's Promise object.

    see

    ``

    since

    1.5

    example

    ​ ````Create a Deferred and set two timer-based functions to either resolve or reject the Deferred after a random interval. Whichever one fires first "wins" and will call one of the callbacks. The second timeout has no effect since the Deferred is already complete (in a resolved or rejected state) from the first timeout action. Also set a timer-based progress notification function, and call a progress handler that adds "working..." to the document body.

    function asyncEvent() {
    var dfd = jQuery.Deferred();

    // Resolve after a random interval
    setTimeout(function() {
    dfd.resolve( "hurray" );
    }, Math.floor( 400 + Math.random() * 2000 ) );

    // Reject after a random interval
    setTimeout(function() {
    dfd.reject( "sorry" );
    }, Math.floor( 400 + Math.random() * 2000 ) );

    // Show a "working..." message every half-second
    setTimeout(function working() {
    if ( dfd.state() === "pending" ) {
    dfd.notify( "working... " );
    setTimeout( working, 500 );
    }
    }, 1 );

    // Return the Promise so caller can't change the Deferred
    return dfd.promise();
    }

    // Attach a done, fail, and progress handler for the asyncEvent
    $.when( asyncEvent() ).then(
    function( status ) {
    alert( status + ", things are going well" );
    },
    function( status ) {
    alert( status + ", you fail this time" );
    },
    function( status ) {
    $( "body" ).append( status );
    }
    );

    Returns Promise<TR, TJ, TN>

  • reject(...args: TJ[]): Deferred<TR, TJ, TN>
  • Reject a Deferred object and call any failCallbacks with the given args.

    see

    ``

    since

    1.5

    Parameters

    • Rest ...args: TJ[]

      Optional arguments that are passed to the failCallbacks.

    Returns Deferred<TR, TJ, TN>

  • rejectWith(context: object, args?: ArrayLike<TJ>): Deferred<TR, TJ, TN>
  • Reject a Deferred object and call any failCallbacks with the given context and args.

    see

    ``

    since

    1.5

    Parameters

    • context: object

      Context passed to the failCallbacks as the this object.

    • Optional args: ArrayLike<TJ>

      An optional array of arguments that are passed to the failCallbacks.

    Returns Deferred<TR, TJ, TN>

  • resolve(...args: TR[]): Deferred<TR, TJ, TN>
  • Resolve a Deferred object and call any doneCallbacks with the given args.

    see

    ``

    since

    1.5

    Parameters

    • Rest ...args: TR[]

      Optional arguments that are passed to the doneCallbacks.

    Returns Deferred<TR, TJ, TN>

  • resolveWith(context: object, args?: ArrayLike<TR>): Deferred<TR, TJ, TN>
  • Resolve a Deferred object and call any doneCallbacks with the given context and args.

    see

    ``

    since

    1.5

    Parameters

    • context: object

      Context passed to the doneCallbacks as the this object.

    • Optional args: ArrayLike<TR>

      An optional array of arguments that are passed to the doneCallbacks.

    Returns Deferred<TR, TJ, TN>

  • state(): "pending" | "resolved" | "rejected"
  • Determine the current state of a Deferred object.

    see

    ``

    since

    1.7

    Returns "pending" | "resolved" | "rejected"

  • then<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND, ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF, ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>), progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARD | ARF | ARP, AJD | AJF | AJP, AND | ANF | ANP, BRD | BRF | BRP, BJD | BJF | BJP, BND | BNF | BNP, CRD | CRF | CRP, CJD | CJF | CJP, CND | CNF | CNP, RRD | RRF | RRP, RJD | RJF | RJP, RND | RNF | RNP>
  • then<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF, ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: null, failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>), progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARF | ARP, AJF | AJP, ANF | ANP, BRF | BRP, BJF | BJP, BNF | BNP, CRF | CRP, CJF | CJP, CNF | CNP, RRF | RRP, RJF | RJP, RNF | RNP>
  • then<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND, ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter: null, progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARD | ARP, AJD | AJP, AND | ANP, BRD | BRP, BJD | BJP, BND | BNP, CRD | CRP, CJD | CJP, CND | CNP, RRD | RRP, RJD | RJP, RND | RNP>
  • then<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>(doneFilter: null, failFilter: null, progressFilter?: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)): PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>
  • then<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND, ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>), progressFilter?: null): PromiseBase<ARD | ARF, AJD | AJF, AND | ANF, BRD | BRF, BJD | BJF, BND | BNF, CRD | CRF, CJD | CJF, CND | CNF, RRD | RRF, RJD | RJF, RND | RNF>
  • then<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>(doneFilter: null, failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>), progressFilter?: null): PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>
  • then<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND>(doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>), failFilter?: null, progressFilter?: null): PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND>
  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can attach handlers using the .then method.

    $.get( "test.php" ).then(
    function() {
    alert( "$.get succeeded" );
    }, function() {
    alert( "$.get failed!" );
    }
    );
    example

    ​ ````Filter the resolve value:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>deferred.then demo</title>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    </head>
    <body>

    <button>Filter Resolve</button>
    <p></p>

    <script>
    var filterResolve = function() {
    var defer = $.Deferred(),
    filtered = defer.then(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    $( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
    });
    };

    $( "button" ).on( "click", filterResolve );
    </script>

    </body>
    </html>
    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.then( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      A function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>
        • Parameters

          • Rest ...t: TJ[]

          Returns ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>

    • progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARD | ARF | ARP, AJD | AJF | AJP, AND | ANF | ANP, BRD | BRF | BRP, BJD | BJF | BJP, BND | BNF | BNP, CRD | CRF | CRP, CJD | CJF | CJP, CND | CNF | CNP, RRD | RRF | RRP, RJD | RJF | RJP, RND | RNF | RNP>

  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.then( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: null

      A function that is called when the Deferred is resolved.

    • failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>
        • Parameters

          • Rest ...t: TJ[]

          Returns ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>

    • progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARF | ARP, AJF | AJP, ANF | ANP, BRF | BRP, BJF | BJP, BNF | BNP, CRF | CRP, CJF | CJP, CNF | CNP, RRF | RRP, RJF | RJP, RNF | RNP>

  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Filter the resolve value:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>deferred.then demo</title>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    </head>
    <body>

    <button>Filter Resolve</button>
    <p></p>

    <script>
    var filterResolve = function() {
    var defer = $.Deferred(),
    filtered = defer.then(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    $( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
    });
    };

    $( "button" ).on( "click", filterResolve );
    </script>

    </body>
    </html>
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      A function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • failFilter: null

      An optional function that is called when the Deferred is rejected.

    • progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARD | ARP, AJD | AJP, AND | ANP, BRD | BRP, BJD | BJP, BND | BNP, CRD | CRP, CJD | CJP, CND | CNP, RRD | RRP, RJD | RJP, RND | RNP>

  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARP = never

    • AJP = never

    • ANP = never

    • BRP = never

    • BJP = never

    • BNP = never

    • CRP = never

    • CJP = never

    • CNP = never

    • RRP = never

    • RJP = never

    • RNP = never

    Parameters

    • doneFilter: null

      A function that is called when the Deferred is resolved.

    • failFilter: null

      An optional function that is called when the Deferred is rejected.

    • Optional progressFilter: ((...t: TN[]) => ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>)

      An optional function that is called when progress notifications are sent to the Deferred.

        • (...t: TN[]): ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>
        • Parameters

          • Rest ...t: TN[]

          Returns ANP | PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP> | Thenable<ANP>

    Returns PromiseBase<ARP, AJP, ANP, BRP, BJP, BNP, CRP, CJP, CNP, RRP, RJP, RNP>

  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can attach handlers using the .then method.

    $.get( "test.php" ).then(
    function() {
    alert( "$.get succeeded" );
    }, function() {
    alert( "$.get failed!" );
    }
    );
    example

    ​ ````Filter the resolve value:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>deferred.then demo</title>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    </head>
    <body>

    <button>Filter Resolve</button>
    <p></p>

    <script>
    var filterResolve = function() {
    var defer = $.Deferred(),
    filtered = defer.then(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    $( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
    });
    };

    $( "button" ).on( "click", filterResolve );
    </script>

    </body>
    </html>
    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.then( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      An optional function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>
        • Parameters

          • Rest ...t: TJ[]

          Returns ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>

    • Optional progressFilter: null

      An optional function that is called when progress notifications are sent to the Deferred.

    Returns PromiseBase<ARD | ARF, AJD | AJF, AND | ANF, BRD | BRF, BJD | BJF, BND | BNF, CRD | CRF, CJD | CJF, CND | CNF, RRD | RRF, RJD | RJF, RND | RNF>

  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Filter reject value:

    var defer = $.Deferred(),
    filtered = defer.then( null, function( value ) {
    return value * 3;
    });

    defer.reject( 6 );
    filtered.fail(function( value ) {
    alert( "Value is ( 3*6 = ) 18: " + value );
    });
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARF = never

    • AJF = never

    • ANF = never

    • BRF = never

    • BJF = never

    • BNF = never

    • CRF = never

    • CJF = never

    • CNF = never

    • RRF = never

    • RJF = never

    • RNF = never

    Parameters

    • doneFilter: null

      An optional function that is called when the Deferred is resolved.

    • failFilter: ((...t: TJ[]) => ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>)

      An optional function that is called when the Deferred is rejected.

        • (...t: TJ[]): ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>
        • Parameters

          • Rest ...t: TJ[]

          Returns ARF | PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF> | Thenable<ARF>

    • Optional progressFilter: null

      An optional function that is called when progress notifications are sent to the Deferred.

    Returns PromiseBase<ARF, AJF, ANF, BRF, BJF, BNF, CRF, CJF, CNF, RRF, RJF, RNF>

  • Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.

    see

    ``

    since

    1.8

    example

    ​ ````Filter the resolve value:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>deferred.then demo</title>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    </head>
    <body>

    <button>Filter Resolve</button>
    <p></p>

    <script>
    var filterResolve = function() {
    var defer = $.Deferred(),
    filtered = defer.then(function( value ) {
    return value * 2;
    });

    defer.resolve( 5 );
    filtered.done(function( value ) {
    $( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
    });
    };

    $( "button" ).on( "click", filterResolve );
    </script>

    </body>
    </html>
    example

    ​ ````Chain tasks:

    var request = $.ajax( url, { dataType: "json" } ),
    chained = request.then(function( data ) {
    return $.ajax( url2, { data: { user: data.userId } } );
    });

    chained.done(function( data ) {
    // data retrieved from url2 as provided by the first request
    });

    Type Parameters

    • ARD = never

    • AJD = never

    • AND = never

    • BRD = never

    • BJD = never

    • BND = never

    • CRD = never

    • CJD = never

    • CND = never

    • RRD = never

    • RJD = never

    • RND = never

    Parameters

    • doneFilter: ((...t: TR[]) => ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>)

      An optional function that is called when the Deferred is resolved.

        • (...t: TR[]): ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>
        • Parameters

          • Rest ...t: TR[]

          Returns ARD | PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND> | Thenable<ARD>

    • Optional failFilter: null

      An optional function that is called when the Deferred is rejected.

    • Optional progressFilter: null

      An optional function that is called when progress notifications are sent to the Deferred.

    Returns PromiseBase<ARD, AJD, AND, BRD, BJD, BND, CRD, CJD, CND, RRD, RJD, RND>

Generated using TypeDoc