Hello, I have a script that updates a table when there are new entries in the database. It pulls a time from the last row in the table and then grabs all the entries that were entered since then.
It runs fine the first time, it grabs the new entries and updates the table. When it runs the second time, however, it will use that initial timestamp and not retrieve the current last entry that was just pulled from the database.
So it seems like the PeriodicalExecuter function loads the page's html when it starts and fails to account for any asynchronous updates or it merely saves that initial time. Is there anyway to get around this?
Here's some code:
new PeriodicalExecuter(function() {
new Ajax.Request(
'#{url}&since_ts=' + $$('#posts tr:last-child td.description')[0].innerHTML.match(/Posted at: (\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})/)[1],
{asynchronous:true,
evalScripts:true,
parameters:'authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')
}
)
}, 60)
I am fairly new to javascript and I would greatly appreciate any help.
Thanks!