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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:21:48+00:00 2026-06-01T11:21:48+00:00

Currently I’m trying to populate a site dynamically. When I step through the code,

  • 0

Currently I’m trying to populate a site dynamically. When I step through the code, it works perfect. However, when I run it on page load as intended, it doesn’t work. The relevant code is:

<body onload="populate_all(string)";>

function populate_all(string)
{
  var split = string.split(" ");
  for(i = 0; i < split.length; i++)
  {
    populate(split[i], 'main'); 
  }
} 

function populate(string, location)
{
  if (string.length==0)
  { 
   document.getElementById(location).innerHTML="";
   return;
  }

  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.onreadystatechange=function()
 {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
        var divTag = document.createElement("div");

        divTag.className ="info";

        divTag.innerHTML = xmlhttp.responseText;

        document.getElementById(location).appendChild(divTag);
  }
 }
 xmlhttp.open("GET","populate.php?string="+string,true);
 xmlhttp.send();
 }

I’ve read up on this issue enough to be pretty sure the php isn’t the issue. Basically: I’m running a javascript function with AJAX several times in a loop and the code only works when I debug it. Thanks for the help!

  • 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-01T11:21:50+00:00Added an answer on June 1, 2026 at 11:21 am
    1. Declare xmlhttp locally.
    2. Use a different variable name as location. location is a global variable, which holds properties and methods to manipulate the current location.

      function populate(string, s_location) {
          var xmlhttp;
      

    Currently, you keep overwriting the xmlhttp variable in the populate method. As a result, the xmlhttp object points to the last request.

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

Sidebar

Related Questions

Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently I'm trying to write my first Python library and I've encountered the following
Currently I have in my code tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addCompoundToLabel:)]; My code
Currently I'm learning C++ and I've been trying to create a simple image processing
Currently I’m trying to get the hang of a block copy with my current
Currently in my webpage i load images to the ListView object as follows... <ContentTemplate>
Currently unable to get my rss feed to validate through W3C RSS Validator .
Currently I am using a pretty basic function to pre-load images: function preload(arrayOfImages) {
Currently running this code to open Business Vision (an application written by someone else
Currently I am trying to implement a timer class in VBA. For that purpose

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.