Jump to content

multiple ajax periodicalUpdater problem. (only works with 1 at a time)


shortysbest

Recommended Posts

I am building a website and it has a few notification areas that i am using ajax to automatically update on a set time, so far i have two functions that need to load onpage load, if i just have one function one works, but if i put the other that works, they wont work together though. So i was wondering why this might be?

 

<body onload="getEmail();getNotifications()">

 

/////////////////EMAIL NOTIFICATIONS/////////////////
//auto retrieve new emails
function getEmail()
{
   new Ajax.PeriodicalUpdater('email-notifier', 'php/notifications/get_emails.php', {
     method: 'get', frequency: 1, decay: 1
   });
setTimout("getEmail()", 6000);
}


////////////////NOTIFICATIONS///////////////
//friend requests
function getNotifications()
{
   new Ajax.PeriodicalUpdater('notifications', 'php/notifications/get_notifications.php', {
     method: 'get', frequency: 1, decay: 1
   });
setTimout("getNotifications()", 6000);
}

A quick search shows you are using Prototype, but your logic is wrong. If you ever wanted to stop it, you'd want to assign that to a global variable. If not, just the following would work

new Ajax.PeriodicalUpdater('email-notifier', 'php/notifications/get_emails.php', {
     method: 'get', frequency: 1, decay: 1
   });

without the functions and javascript timeout.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.