1

I have a list of "online users", which I refresh every 30 seconds with Ajax.PeriodicalUpdater from prototype.js.

There is an issue, that if a user has two tabs/windows open with the site, logs out in one of them, the PeriodicalUpdater is not canceled.

This means that PeriodicalUpdater updates my block element with the entire login page, as I have a restful authentication, that redirects to that.

I am using PHP sessions, and I really cannot get my head straight on this one.

Can any of you guys point me in the right direction?

4

2 回答 2

0

When creating the PE, keep a reference to it:

// At global scope, or ideally if you have a namespaced object, use that
var thePE;

// Where you create the PE
thePE = new PeriodicalExecuter(yourFunction, 3);

And when you want it to stop, tell it to stop (assuming it has been started):

if (thePE) {
    thePE.stop();
    thePE = undefined;
}

(PeriodicalExecuter#stop docs here.)

于 2009-08-22T12:56:20.190 回答
0

I would consider changing the method that returns the results so that it doesn't require an authenticated session to access it, but it returns valid information only when there is an authenticated session. Otherwise, it returns a value indicating that the updates should cease and a suitable message for display in your online user's block. This would mean that you'd probably need to return JSON instead -- not a bad thing -- and either combine it with an HTML snippet as part of the JSON or simply construct the HTML on the client from the JSON data (better IMO since the view is the correct place to do mark up).

于 2009-08-22T13:01:24.933 回答