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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:42:33+00:00 2026-06-07T12:42:33+00:00

I have the following code: $(document).ready(function () { $(‘div.env’).each(function (index, item) { var vm

  • 0

I have the following code:

$(document).ready(function () {

        $('div.env').each(function (index, item) {

            var vm = $(item).text();
            alert(vm);
            var url = "http://localhost:56656/HTML" + vm + ".htm";
            alert(url);
            $.ajax(url, {
                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 () {
                    alert("Error");
                    $('div').css('background', '#f00');
                }
            });

        });

The problem is that I have an alert for each value inside the div class “env” before the Ajax function is executed.

What I want is, for each div, get the value, perform the ajax, get next next value. It seems the ajax is being performed entirely at the end.

Any help appreciated, Thanks.

  • 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-07T12:42:35+00:00Added an answer on June 7, 2026 at 12:42 pm

    Ajax calls are asynchronous by default, so your loop will continue to execute and quite possibly complete before even the first ajax call is completed.

    Having ajax calls in a loop doesn’t seem like a great way to go to be honest – If I was you I would try a different approach.

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

Sidebar

Related Questions

I have a following code: $(document).ready(function() { $('a[rel]').each(function() { $(this).qtip( { content: { text:
I have the following code: $(document).ready(function() { var ul = $(<div>); ul.addClass(menu).appendTo('.menuwrapper'); }); function
I have the following code: $(document).ready(function() { var id = 'cbx'; var idPrefix =
I have the following JQuery code: $(document).ready(function () { var $containerHeight = $(window).height(); if
Under $(document).ready(function() , I have the following code: num = $(#mainContentCategoryLinksWrapper > div).size(); This
I have the following code: <script> $(document).ready(function() { $('.toggle_section').click(function(e){ parent = $(e.target).closest(div) objChild =
I have the following code: $(document).ready(function() { $('.container').ready(function() { var v = new Video($(this));
I have the following code: $(document).ready(function(){ $(.datepicker).each(function() { $(this).datepicker({ beforeShowDay: function(date){ return [$(this).parent().find(span.days).html(), ]
So I have the following code: <script type=text/javascript> $(document).ready( function () { $(#txt).click(function ()
I have the following code which works: $(document).ready(function() { var xhr = false; func_two();

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.