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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:39:13+00:00 2026-05-18T07:39:13+00:00

Hey there, I’m working on a jQuery each()-loop containing an ajax-request an a setTimeout.

  • 0

Hey there,
I’m working on a jQuery each()-loop containing an ajax-request an a setTimeout. That’s giving me some issues with the program flow.

xml_queries: function (data) {
    var values = [];

    // ...

    $.each(data, function(index, value) {

        // ...

        // Start xml query
        var i = 0;
        get_data(value.value);

        function get_data(value) {
            $.ajax({
                type: 'POST',
                url: '/admin/scanner/get_music_data/' + value,
                dataTaype: 'json',
                success: function(response) {
                    if ( response === 'FALSE' ) {
                        // Start recursion - up to 3 Retries
                        if ( ++i <= 3 ) {
                            setTimeout(function() {
                                get_data();
                            }, 100);
                        } else {
                            // ...
                        }
                    } else {
                        values.push(response);
                    }
                }
            });
        }
    });
    // return values;
    console.log(values);
}

My problem is that the console.log() in the last line is fired immediatly (while the loop is still processing data). Isn’t there any easy possibility to wait for the loop to finish? \:

Best regards!

  • 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-18T07:39:14+00:00Added an answer on May 18, 2026 at 7:39 am

    Based on your current code, the most straightforward way would be to set $.ajax’s async option to false, to force a synchronous request, causing JavaScript to wait for it to complete before continuing to execute the subsequent statements (it won’t do this for asynchronous requests).

    $.ajax(
       {
        type: 'POST',
        async: false,
        ...
    

    That will block your browser for the duration of each request (yuck). Another way to do it would be to redesign your application such that the next ajax call is called from within the success callback of the first, e.g.:

    $.ajax(
       {
        type: 'POST',
        ...
        success: function() {
            doAjaxThingie();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey there, i have quite some issues with the mode rewrite here is what
hey there.. need some advice again :) I'm working on a project with a
Hey there, I've got a block of HTML that I'm going to be using
hey there, i have a div that expands when the page is loaded, now
Hey there. I'm trying to write a small program that will read the four
Hey there you lot, is there a way that I can open a lightbox
Hey there. I have a c# application that parses txt files and imports the
Hey there, Now im working this base on dmitko tutorial on extending django-registration post
hey there i am having problem i have List<List<memoryCard>> that i want to show
Hey there. I have an image that I am absolutely positioning. In Firefox it

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.