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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:00:36+00:00 2026-05-29T23:00:36+00:00

I have javascript/jquery code which fetches info and updates it into the database with

  • 0

I have javascript/jquery code which fetches info and updates it into the database with a mixture of while/for loops. While fetching, I have a div which shows a current progress log of whats going on. In Firefox, as the script is running it updates the div at the same time as it should. In Google Chrome, it runs the entire loop, holding back the log, and only outputs it until the script is finished running. Anyone have any idea why this is happening?

Here is my code:

$(document).ready(function() {
    add_text("test");

    var array_length = num_sets;

    for(var i = 0; i < array_length; i = i + 1) {
        var setId = sets[i]['id'];
        var setName = sets[i]['name'];
        var setLinkName = sets[i]['link'];
        var setNumCards = sets[i]['num_cards'];

        add_text("Beginning to fetch set \"" + setName + "\"");
        add_text("Found " + setNumCards + " total cards.");

        while(ii < setNumCards) {
            var card_name = sets[i]['cards'][ii]['name'];
            var card_link = sets[i]['cards'][ii]['link'];
            add_text("Fetching card " + sets[i]['cards'][ii]['name']);

            fetch_card(sets[i]['cards'][ii]['link'], setId);
        }

    }
});

add_text function:

function add_text(text) {
    $("#status_text").append("<br />" + text);
}

fetch_card function:

function fetch_card(card_link, set_id)
{
    $.ajax({
      url: "fetch_card.php?link=" + card_link + "&set_id=" + set_id,
      context: document.body,
      async: false,
      success: function(){
        ii = ii + 1;
      }
    });
}
  • 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-29T23:00:37+00:00Added an answer on May 29, 2026 at 11:00 pm

    You are using synchronous ajax calls (which are generally not very desirable). The browser can block all activity until that ajax call completes. Whether or not the browser updates the screen during a synchronous ajax call is up to the browser.

    Your code would be much better if it was rewritten to use asychronous ajax only. It takes a little more work to structure your code properly to work with asynchronous ajax calls, but the browser remains completely responsive during the asynchronous ajax calls.

    I’m not entirely sure how you were using the ii variable in your original implementation (as it wasn’t declared or initialized in the code you included), but this is the general structure you could use. It uses the traditional for loop to collect all the data you wanted in an array, then calls the ajax function one a time on that data. It isn’t clear to me how you’re actually doing anything with the returned ajax info, but perhaps that just isn’t something you included here:

    $(document).ready(function() {
        add_text("test");
    
        var array_length = num_sets;
        var fetchData = [];
        var fetchIndex = 0;
    
        for(var i = 0; i < array_length; i++) {
            var setId = sets[i]['id'];
            var setName = sets[i]['name'];
            var setLinkName = sets[i]['link'];
            var setNumCards = sets[i]['num_cards'];
    
            add_text("Beginning to fetch set \"" + setName + "\"");
            add_text("Found " + setNumCards + " total cards.");
            for (var ii = 0; ii < setNumCards; ii++) {
                var card_name = sets[i]['cards'][ii]['name'];
                var card_link = sets[i]['cards'][ii]['link'];
                add_text("Fetching card " + sets[i]['cards'][ii]['name']);
                fetchData.push({link: sets[i]['cards'][ii]['link'], id: setId});
            }
        }
    
        function next() {
            if (fetchIndex < fetchData.length) {
                fetch_card(fetchData[fetchIndex].link, fetchData[fetchIndex].id, next);
                fetchIndex++;
            }
        }
    
        function fetch_card(card_link, set_id, successFn) {
            $.ajax({
              url: "fetch_card.php?link=" + card_link + "&set_id=" + set_id,
              context: document.body,
              async: true,
              success: successFn
            });
        }
    
        next();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this javascript code to which i want to add the jquery fade-in
I have the following JavaScript code which I like to convert to jQuery but
index.php has this jquery code which loads notifications.inc.php into a div on the page
I have a very simple Javascript (jQuery) code, which just add a class name
I have problems with the following bit of javascript/jquery code: this.droppable = function(){ $('.imageWindow
I have some jQuery/JavaScript code that I want to run only when there is
I have this javascript code below that uses jquery, it is suppoed to be
I have the following code in a jQuery JavaScript document running on a page
I have the following code in JavaScript and jQuery: $(<li />) .html('Some HTML') I
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script

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.