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 6383951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:42:49+00:00 2026-05-25T02:42:49+00:00

I’m currently working on a project which uses many ajax requests to access data

  • 0

I’m currently working on a project which uses many ajax requests to access data from restfull services. Some operations require multiple sequential calls. As soon as i implemented the first of these i ran into race conditions. (calling ajaxCall_1, then ajaxCall_2, which uses the result of ajaxCall_1, but ajaxCall_1 had not returned yet). Of course I could use the .success property, but that does not do the trick for me. Let me explain with a simplified example below. I’ve got a .js file containing:

function getServerBoolean(){
    $.get('url_1',function(data){return data)});
}

function refreshWidget(){
    $.get('url_2',function(data){
        var serverBoolean = getServerBoolean(); 
        --do some html building here based on boolean returned from server-- }
    );
}

function setServerValue(newValue){
   $.post('url',{key:newValue},function(data){
      // server model has changed, so refresh widget. 
      refreshWidget();
   });

}

Whenever I call setServerValeu(‘someValue’), the widget needs to refresh itself, but before doing this it needs to know the server boolean value. In this fashion I have many more siutations, so simply giving a callback as a method argument and then calling it in .success() does not do the trick for me.

I stumbled upon the $.when $.then $.done methods, but am not sure how to use these for my situation. Is there anybody who might be able to help me how to set this up?

Thanks in advance!

Richard

  • 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-05-25T02:42:50+00:00Added an answer on May 25, 2026 at 2:42 am

    I don’t know about $.when $then $done, but functional way of doing this would be to pass callbacks around. It could look like that:

    function getServerBoolean(dataCallback){
        $.get('url_1', dataCallback);
    }
    
    function refreshWidget(){
        $.get('url_2',function(data){
            getServerBoolean(function(boolValueReturned) {
               //do something with the value
            });
        });
    }
    

    Of course there could be numerous way to tweak this, like for example checking (in getServerBoolean) if the argument we got is a function and if not set it to some default callback.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.