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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:05:57+00:00 2026-05-22T17:05:57+00:00

UPDATE Following @Ryan Olds suggestion to include the setTimeout in the callback, I must

  • 0

UPDATE Following @Ryan Olds suggestion to include the setTimeout in the callback, I must clarify that in my production code I’m calling multiple urls to get json data from several sites. (Have updated JavaScript code below).

Is it only possible to have multiple timeouts scattered throughout this function?


I have a self-invoking updateFunction as follows:

(function update() {
  $.ajax({
    type: 'GET',
    url: "http://myexample.com/jsondata",
    dataType: 'json',
    success: function (data) {
      // do some callback stuff
    },
    async: false
  });

 $.ajax({
    type: 'GET',
    url: "http://myexample2.com/jsondata2",
    dataType: 'json',
    success: function (data) {
      // do some further callback stuff
    },
    async: false
  });

  setTimeout(update, 2000);
})();

What I expected this code to do

I hoped that this function would go off to the target URL and wait for the result, then deal with the success callback. Then (and only then) would it fall through to set a 2 second timeout to call the function again.

What appears to be happening instead

Instead, the GET request codes out, and before the response has been dealt with, the timeout has already been set.

What am I missing? How can I make this entirely synchronous?

  • 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-22T17:05:58+00:00Added an answer on May 22, 2026 at 5:05 pm

    If I were you, I’d make use of jQuery’s support for deferred action.

    (function update() {
        $.when($.ajax({
            type: 'GET',
            url: "http://myexample.com/jsondata",
            dataType: 'json',
            success: function (data) {
                // do some callback stuff
            }
        }), $.ajax({
            type: 'GET',
            url: "http://myexample2.com/jsondata2",
            dataType: 'json',
            success: function (data) {
                // do some further callback stuff
            }
        }), $.ajax({
            // more requests as you like
        })).then(function() {
            // when all the requests are complete
            setTimeout(update, 2000);
        });
    }());
    

    Much nicer, IMHO, than mucking around with synchronous requests. Indeed, if the requests are cross-domain, this is pretty much your only option.

    See

    • $.when
    • deferred.then
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: UPDATE myTable SET Col1 = @Value However, I have
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I'm running the following code to update the database according to the data I
I'm using the following code to update a DataGridView's cell value. This is called
Could someone update the following code to make the cookie expire in 30 seconds.
I'll like to update the following rewrite condition to only allow one particular subdomain.
Does Ado.net check if the following update is required? ADDRESS table with a TOWN
I have the following query: UPDATE lessonstatus INNER JOIN user ON lessonstatus.user_id = user.user_id
What is the order of evaluation in the following query: UPDATE tbl SET q
Currently I have to write the following to update an element already contained in

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.