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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:03:41+00:00 2026-06-10T10:03:41+00:00

Note: simplified example.. I’ve got a page with 1000 table rows. For each row,

  • 0

Note: simplified example..

I’ve got a page with 1000 table rows. For each row, i need to “do some work” on the server via an AJAX call, then in the callback, update that table row saying done.

Initially i tried just firing off the 1000 ajax requests inside the .each selector, but the browser was locking up.

So i changed it to try and use an internal ajax counter, so only ever fire off 50 at a time.

Here’s the code:

$('#do').click(function () {
    var maxAjaxRequests = 50;
    var ajaxRequests = 0;
    var doneCounter = 0;
    var toDo = $('#mytable tr').length;

    $.each($('#mytable > tr'), function (i, v) {
        while (doneCounter < toDo) {
            if (ajaxRequests <= maxAjaxRequests) {
                ajaxRequests++;
                doAsyncStuff($(this), function () {
                    ajaxRequests--;
                    doneCounter++;
                });
            } else {
                setTimeout(function() {
                }, 1000);
            }
        }
    });
});

function doAsyncStuff(tr, completeCallback) {   
    $.ajax({
        url: '/somewhere',
        type: 'POST',
        dataType: 'json',
        data: null,
        contentType: 'application/json; charset=utf-8',
        complete: function () {
            completeCallback();
        },
        success: function (json) {
            // update ui.
        },
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            // update ui.
        }
    });
}

But the browser is still being locked up. It never goes into the $.ajax complete callback, even though i can see the request coming back successfully (via Fiddler). Therefore its just sleeping, looping, sleeping, etc because the callback is never returned.

I’ve got a feeling that the entire doAsyncStuff function needs to be asynchronous?

Any ideas on what i am doing wrong (or how i can do this better)?

  • 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-06-10T10:03:42+00:00Added an answer on June 10, 2026 at 10:03 am

    You are doing a while loop inside the .each callback function, so there is much more ajax request than 1000, the worst is 1000*1000.

    You could delay each ajax request with different time.

    $('#do').click(function () {
        $('#mytable > tr').each(function (i, v) {
            var $this = $(this);
            setTimeout(function () {
                doAsyncStuff($this, function () {
                   console.log('complete!');
                });
            }, i * 10);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note that all the code is a simplified example in order to only communicate
[Note : I've simplified my example for clarity] Let's say that I have a
Here's a simplified example of my problem. I have a table where there's a
I mistakenly committed the wrong change to file, for a simplified example's sake let's
Note: I changed the example from when I first posted. My first example was
Simplified for example, I have two tables, groups and items . items ( id,
My simplified and contrived example is the following:- Lets say that I want to
Given the example queries below (Simplified examples only) DECLARE @DT int; SET @DT=20110717; --
I have xml input which looks like (simplified version used for example): <Student> <Subject>
I have a django template which loops over many notes/comments. As a simplified example

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.