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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:19:21+00:00 2026-05-31T09:19:21+00:00

var tds = ["0", "1", "2", "3", "4", "5", "6"]; for (var i =

  • 0
var tds = ["0", "1", "2", "3", "4", "5", "6"];

for (var i = 0; i < tds.length; i++) {

    jQuery("#notification-bar").html('I am doing ' + tds[i]);

    jQuery.ajax({
        url: "/ajax_json_echo/",
        type: "POST",
        timeout: 10000,
        data: tds[i],
        success: function(response) {
       
        },
        error: function(x, t, m) {
        
 
        }
    });


} //end for

jQuery("#notification-bar").html("Done!");​

/ajax_json_echo/ might take 10 seconds or even more to deal with tds.

The expected result of notification bar is

I am doing 0

I am doing 1

I am doing 2

…

Done!

The actual result I get is:

Done!

I guess it is caused by the async variable of jquery ajax is being set to true.

If it is set to false, the browser will be frozen. When it recovers, I get "Done!" only.

  • 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-31T09:19:22+00:00Added an answer on May 31, 2026 at 9:19 am

    The browser runs JavaScript and does page rendering all on the same thread, so while JS is running no repaints will occur. This means that your entire for loop will complete and the status message will be set to “Done!” before the page gets updated.

    In the case of async being true all of the Ajax requests are queued up initially and the message set to “Done!” and then the responses are processed later asynchronously. In the case of async set to false the Ajax requests are done one at a time with no further action until the response comes in. Either way the browser never gets a chance to display the “I am doing…” messages.

    Rather than using a loop you can trigger each subsequent call from within the Ajax complete (or success) callback:

    var tds = ["0", "1", "2", "3", "4", "5", "6"];
    
    function doNextAjax(i) {
       if (i < tds.length) {
          jQuery("#notification-bar").html('I am doing ' + tds[i]);
    
          jQuery.ajax({
             url: "/ajax_json_echo/",
             type: "POST",
             timeout: 10000,
             data: tds[i],
             success: function(response) {
    
             },
             error: function(x, t, m) {    
    
             },
             complete: function() {
                doNextAjax(i + 1);
             }
          });
       } else {
          jQuery("#notification-bar").html("Done!");​
       }
    }
    
    doNextAjax(0);
    

    Each time doNextAjax() is called it updates the status message and makes a single Ajax request and that’s all. When the function exits the browser then has a chance to re-render and actually show that message. Then when the complete callback is fired it calls the function again for the next item. When there are no items left it sets the “Done!” message.

    Note that using the complete callback to trigger the next Ajax call means that it will keep going even if a particular request fails. If you wanted to stop on error you could get rid of the complete handler and move the doNextAjax(i+1) into the success callback.

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

Sidebar

Related Questions

var htm = $.ajax({ type: GET, url: ./viewforms, async: false }).responseText; var myObject =
I am retrieving HTML from a remote host with the following jQuery code var
var foo = { someKey: someValue }; var bar = someKey; How do I
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
Here's my code: <html> <header> <title>Checkup Date</title> <script type=text/javascript> function datechange() { if (window.XMLHttpRequest)
I'm facing a troubles around jQuery and HTML elements. Let's to the Artists: <table
var a = [1,4,5]; var e = a.length--; Here e variable will contain 5.
Okay i have a HTML TABLE , with 4 TDs in a TR(tow) as
var boxIdValue = 233; var result = title + '<br/>@Html.ActionLink(Detail, Show, Boxes, new{boxId=233}, null)';
var widgetOverlay = jQuery('#widgetOverlay'); var widgetOpen = jQuery('#widgetOpen a'); var widgetOverlayHeight = widgetOverlay.height() -

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.