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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:59:21+00:00 2026-06-07T07:59:21+00:00

I have currently got the following code which will run a bunch of ajax

  • 0

I have currently got the following code which will run a bunch of ajax requests (40-50) then do them all again. (So do them forever essentially)

Code:

 $(document).ready(function () {
        window.setInterval(function () {
            $('div.env').each(function (index, item) {
                var vm = $(item).text();                    
                var env = "http://localhost:56656/HTML" + vm + ".htm";
                $.ajax(env, {
                    async: false,
                    URL: env,
                    type: "GET",
                    dataType: "html",
                    success: function (data) {
                        //alert("Colouring");
                        var style = $(data).filter('div').attr('style');
                        var styleObj = {};
                        $.each(style.split(';'), function () {
                            var rule = this.split(':');
                            styleObj[$.trim(rule[0])] = $.trim(rule[1]);
                        });

                        $(item).css('background', styleObj.background);

                    },
                    error: function () {

                        $(item).css('background', '#f00');
                    }
                });

            });

        }, 10000);
    });

As you can see, I am currently using Timeouts which are running particularly slow on IE and on occasion running slow on chrome. When I say slow, I mean that all the ajax requests will complete then the screen will refresh with the updates. This is the case on IE all the time and occasionally Chrome. Ideally, I would like the ajax to do its requests, update then do the next ajax request.

Any better way to do AJAX requests continually?

Thank you in advance,
James

  • 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-07T07:59:23+00:00Added an answer on June 7, 2026 at 7:59 am

    You may want to use Caolan’s async library. You’re code may look like this (after including async.js of course):

    $(document).ready(function () {
        function call() {
            var calls = [];
            $('div.env').each(function (index, item) {
                calls.push(function(callback) {
                    $.ajax({
                        // DO NOT USE async: false!!!!
                        // some ajax settings
                        complete : function() {
                            callback();
                        }
                    });
                });
            });
            async.parallel(calls, function() {
                /* This will fire when every call finishes.
                   You may want to add timeout here, or else
                   you will end up flooded with requests. */
                call();
            });
        };
    });
    

    You should tune it to your needs (async can handle errors as well, read the documentation). You said that you want them to fire one after another, so use async.series instead of async.parallel.

    BTW This piece of code:

    $.ajax({
        async: false
    

    PURE EVIL!!! Blocks every other script and even entire browser!!! That’s probably the reason for your “slow-and-blink” problem.

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

Sidebar

Related Questions

Hi all i've got the following code which will go off and get all
I have got the following jquery code which appends some html elements to the
I'm looking for some feedback on the following: I currently have two classes, which
I have currently got imagepaths stored within the database and image files stored in
Currently I have create a website using codeigniter. I got a message error every
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I have currently in a table about 90k rows. And it's will grow up
I have four classes which share some arrangement of four properties. I have currently
Backgroup: We are looking at SAS BI Dashboard. We have currently implemented almost all
I currently have a set of buttons which when pressed, update an element of

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.