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!