beauty - I will go with the second example. I am now returning an array with each item containing an array with 4 elements. Looping over this is cool, but see the following HTML:
<div id="60667C7C" class="imStatus"> <img src="/pics/sm_loading.gif"> </div> <div id="604357EC" class="imStatus"> <img src="/pics/sm_loading.gif"> </div> I need to change the src of the image within the ID'd div. But the following doesnt seem to work, how can I sort this out? for(var i = 0; i < r.length; i++){ //alert(r[i][0]) $(r[i][0] + ' > img').attr("src",r[i][1]); } r[i][0] has the id in it, r[i][1] has the image URL. Thanks! On 9/14/07, Erik Beeson <[EMAIL PROTECTED]> wrote: > I don't get how mouseover relates to your timed intervals, but I'd say more > like option A. You could do something like this (untested): > > $(window).load(function() { // don't start refreshing until the whole page > has loaded > setInterval(function() { > $('.myItemsToUpdate').each(function() { > var item = this; > $.ajax({ > url: '...', > data: {id: item.id}, > ..., > success: function(data) { > /* handle response */ > } > }); > }); > }, 30*1000); // 30 seconds > }); > > But more efficient, if you can manage it, would be to make one ajax request > with all of the IDs that you want to update. Something like: > > $(window).load(function() { // don't start refreshing until the whole page > has loaded > var ids = []; > $('.myItemsToUpdate').each(function() { > ids.push( this.id ); > }); > setInterval(function() { > $.ajax({ > url: '...', > data: {id: ids}, > ..., > success: function(data) { > /* handle response, data will need to contain updated data > for each submitted id */ > } > }); > }, 30*1000); // 30 seconds > }); > > Or something. Does that help any? > > --Erik > > > > On 9/13/07, Duncan < [EMAIL PROTECTED] > wrote: > > > > All, > > > > I am trying to get my head around something I haven't had to try and do > before. > > > > Scenario: I have a list of 'traffic lights' on a page, each relating > > to a record with unique id in a table. > > > > I want these lights to update every 30 seconds or so, and they will > > change colour according to the result. > > > > This update will fire an ajax request - I can do this bit - however, > > how should I structure the jquery calls? > > > > Should I > > > > a) give them all a class name and loop over everything with that > > class, fetching the id for each and using it in the ajax? > > b) create a $(document).ready(function(){ function for each of the > > id's and somehow fire them on a timed event? (I can work out how to do > > this with a mouseover). > > > > Sorry if this is fairly uncoherent, but I know what I need to achieve, > > just not sure which way to start! > > > > Any suggestions gratefully received! > > > > Thanks > > > > > > -- > > Duncan I Loxton > > [EMAIL PROTECTED] > > > > -- Duncan I Loxton [EMAIL PROTECTED]