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

  • SEARCH
  • Home
  • 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 8092275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:15:00+00:00 2026-06-05T20:15:00+00:00

I’m having a bit of trouble with jQuery Deferred. I’m using a jQuery ajax

  • 0

I’m having a bit of trouble with jQuery Deferred.

I’m using a jQuery ajax call inside a function wrapper, and I’m attempting to chain two success callbacks one after the other, in order of scope. However, both success callbacks are executing simultaneously, which is causing problems.

My initial function call looks like this (system.log is a smarter console.log.):

serverpaths.setConfig(path).then(system.log("BAM! SERVERPATHS: " + serverpaths));

Inside this setConfig method, I have an AJAX call with a .then() chained to it.
(system.defer is a wrapper that returns a jQuery.Deferred object; http.get is a wrapper for jQuery.ajax.)

config.setConfig = function (configObj) {
    var that = this;
    var inlineHelper = function (data) {
        return system.defer(function (dfd) {
            for (var key in data) {
                system.log("Config[" + key + "]: " + that[key]);
                system.log("Data[" + key + "]: " + data[key]);
                that[key] = data[key];
                system.log("New Config[" + key + "]: " + that[key]);
            }
        }).promise();
    };

    if (typeof configObj === "string") {
        http.get("api/getPathConfig")             // The problem seems to be in this area
            .then(function (data) {
                return system.defer(function () {
                    inlineHelper(data);
                }).promise();
            });
    } else {
        return system.defer(function () {
            inlineHelper(configObj);
        }).promise();
    }
};

Ideally, the ajax request should be called, then inlinehelper should be called, then system.log should be called, because I’m kicking my promise object back up the chain with return statements. The problem here is that the ajax request is called, and then system.log and inlinehelper are called simultaneously.

Has anyone run into a problem like this before? Function scope and async calls seem to be fighting each other here. I’m sure I can figure this out, but it doesn’t seem quite logical – my guess is that when my ajax request fires its success, that triggers the .then() call in my main scope without me wanting it to. I’m sure I could solve this, but it helps to have a great community of devs to bounce thoughts off of.

I appreciate all of your advice. Thank you!

  • 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-05T20:15:01+00:00Added an answer on June 5, 2026 at 8:15 pm

    Doing .then(function() { return promise }) just does nothing. Your returned promise won’t be propagated to the next deferred callback.

    If you want to do this, use .pipe() instead of .then(). This way you will be able to chain promises.

    If you want to chain 3 asynchronous call, do like this :

    firstDeferredCall.pipe(secondDeferredCall).pipe(thirdDeferredCall)
    

    If you write

    firstDeferredCall.then(secondDeferredCall).then(thirdDeferredCall)
    

    thirdDeferredCall won’t wait for secondDeferredCall call to be executed.

    Edit: as tim said, .pipe is deprecated since jQuery 1.8.

    If you are using jQuery 1.8+, you can use .then which now replaces .pipe. See documentation for .then. In this case your code should be good without any modification.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.