My web app currently uses this to kick off notifications retrieval in client-side:
$(document).ready( getNotifications() );
which is great, but i need it to run every XXX seconds, so I've added a setInterval timer at the end of getNotifications()
, here:
function getNotifications() {
//(do stuff)
//now repeat every X seconds (10000 = 10s)
setInterval(getNotifications, 30000);
}
problem -- doing this seems to trigger multiple instances of the timer-loop'd function. using an alert() I can see that every timer cycle creates a new instance set to the timer, not an iteration of the same instance as desired.
how can i get a timer/loop for my functionality without multiple instances?
thanks!