[Javascript] Multiple ajax calls onload

Scott Reynen scott at randomchaos.com
Wed Jul 25 12:01:11 CDT 2007


On Jul 25, 2007, at 10:42 AM, Murphy, Matt wrote:

> All,
>
> I thought I had this ingenious idea, to make a slow-loading page load
> faster, I'd break up the sections into divs, and then call a series of
> ajax functions to populate those divs asynchronously.
>
> Problem is, only the last one called shows up. I can see in the  
> firefox
> error log that both document.getElementById 
> ('mydiv').innerHTML="myhtml"
> calls ran, (the output of the php scripts called) but only one showed
> up.

It's hard to know without looking at your ajaxme() function, but if  
both calls are setting innerHTML on the same div, the last one to run  
is overwriting all the others.  It would be better to change that to  
something like this (untested):

var newDiv = document.createElement( 'div' );
newDiv.innerHTML = "myhtml";
document.getElementById('mydiv').appendChild( newDiv );

Also, please don't use "Reply" to start a new thread.  Some of us are  
using threaded email clients that get confused by that.

Peace,
Scott



More information about the Javascript mailing list