[Javascript] Multiple ajax calls onload

Peter Brunone peter at brunone.com
Wed Jul 25 12:31:49 CDT 2007


What about using an array of objects?  Make the array global, and define each request locally so it goes out of scope...?  Of course if the array is just a pointer, you could try defining each request initially AS an element in the array, e.g.  aRequests[i] = new HttpRequest() (or whatever the syntax is for those things).

Cheers,

Peter

----------------------------------------

From: "Murphy, Matt" Matt.Murphy at thermofisher.com

My apologies on the reply...

Well, this seems to work if I use two different ajaxme scripts with two
different names of the httprequest object. 

So the question is, is there a way to use variable variables like in PHP
to do this? 

So I could name each instance of my httprequest object something
different? 

Matt

-----Original Message-----
From: javascript-bounces at LaTech.edu

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 );

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070725/7bb3268f/attachment.htm>


More information about the Javascript mailing list