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] >