Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:26:13+00:00 2026-06-13T11:26:13+00:00

This code snippet worked in 1.7.2 with both success/error callbacks as well as promises

  • 0

This code snippet worked in 1.7.2 with both success/error callbacks as well as promises style callbacks. With 1.8.2 the success/error callbacks still work but the promises do not. My hunch is that the return dfd.promise(jqXHR); line is the problem but im not certain.

$.ajaxPrefilter(function (options, originalOptions, jqXHR) {

    // Don't infinitely recurse
    originalOptions._retry = isNaN(originalOptions._retry)
        ? Common.auth.maxExpiredAuthorizationRetries
        : originalOptions._retry - 1;

    // set up to date authorization header with every request
    jqXHR.setRequestHeader("Authorization", Common.auth.getAuthorizationHeader());

    // save the original error callback for later
    if (originalOptions.error)
        originalOptions._error = originalOptions.error;

    // overwrite *current request* error callback
    options.error = $.noop();

    // setup our own deferred object to also support promises that are only invoked
    // once all of the retry attempts have been exhausted
    var dfd = $.Deferred();
    jqXHR.done(dfd.resolve);

    // if the request fails, do something else yet still resolve
    jqXHR.fail(function () {
        var args = Array.prototype.slice.call(arguments);

        if (jqXHR.status === 401 && originalOptions._retry > 0) {

            // refresh the oauth credentials for the next attempt(s)
            // (will be stored and returned by Common.auth.getAuthorizationHeader())
            Common.auth.handleUnauthorized();

            // retry with our modified
            $.ajax(originalOptions).then(dfd.resolve, dfd.reject);

        } else {
            // add our _error callback to our promise object
            if (originalOptions._error)
                dfd.fail(originalOptions._error);
            dfd.rejectWith(jqXHR, args);
        }
    });

    // NOW override the jqXHR's promise functions with our deferred
    return dfd.promise(jqXHR);
});

Update: Here is my ajax request that fails:

$.ajax({
        url: someFunctionToGetUrl(),
        // works
        //success: callback,
        //error: ajaxErrorHandler
    }).then(
        [callback],
        [errorback, ajaxErrorHandler]
    );
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:26:14+00:00Added an answer on June 13, 2026 at 11:26 am

    Edit: This is a documentation bug, but the behavior is by design. The api changed such that deferred.then now behaves like deferred.pipe and no longer allows arrays to be passed in, but the documentation hasn’t been updated to reflect that.

    Related bugs:

    • github: deferred.then now behaves like deferred.pipe but the documentation is stale
    • jQuery Bug Tracker: Ticket #12765: deferred.then([SuccessArrayFuncs],failFunc) does not work as described

    The workaround I describe at the end of my original answer below still applies.


    Original answer:

    It looks like a jQuery bug to me. If you pass in a single function reference as the first argument, it works, but not if you pass in an array of functions:

    http://jsfiddle.net/tunDH/

    But, the documentation says an array of functions is just fine:

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

    And, you are right. It does work with jQuery 1.7: http://jsfiddle.net/tunDH/1/

    A workaround would be to wrap all your function calls inside a single function, instead of inside an array:

    $.ajax({ 
        url: someFunctionToGetUrl(), 
        // works 
        //success: callback, 
        //error: ajaxErrorHandler 
    }).then( 
        function(){
            callback1.apply(this, arguments);
            callback2.apply(this, arguments);
        }, 
        [errorback, ajaxErrorHandler] 
    ); 
    

    http://jsfiddle.net/tunDH/2/

    You’ll probably need to do the same thing with the error callbacks, but I didn’t test that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a snippet of code, inserted immediately after creating my grid, that worked fine
Perhaps I'm over-simplifying this by only giving you a small snippet of code (and
Does anyone know what's wrong with the code below? The this->progressBar1->Value part worked by
I'm using this little code snippet to catch Java processes with certain parameters: string
This snippet of code generate huge memory leaks. Could you help me to find
This code is almost taken directly out of a book but it just doesn't
A code snippet is at the bottom of the question I am successfully able
I have a simple piece of code that is giving me a compiler error.
I have a code snippet that checks user logins and gets navigations and etc
This question looks like this one : Programmatically binding List to ListBox but as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.