用户注销时停止 Prototype.js Ajax.PeriodicalUpdater

发布于 2024-08-03 10:46:41 字数 261 浏览 3 评论 0原文

我有一个“在线用户”列表,我使用prototype.js 中的Ajax.PeriodicalUpdater 每30 秒刷新一次。

存在一个问题,如果用户在网站上打开了两个选项卡/窗口,并在其中之一中注销,则周期性更新程序不会被取消。

这意味着 periodicalupdater 使用整个登录页面更新我的块元素,因为我有一个静态身份验证,会重定向到该页面。

我正在使用 PHP 会话,但我真的无法弄清楚这一点。

你们中有人能指出我正确的方向吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2024-08-10 10:46:41

我会考虑更改返回结果的方法,以便不需要经过身份验证的会话来访问它,但仅当存在经过身份验证的会话时才返回有效信息。否则,它会返回一个值,指示更新应该停止,并在您的在线用户块中显示一条合适的消息。这意味着您可能需要返回 JSON ——这不是坏事 ——并且要么将其与 HTML 片段结合起来作为 JSON 的一部分,要么简单地从 JSON 数据在客户端上构建 HTML(在我看来更好,因为该视图是进行标记的正确位置)。

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).

音盲 2024-08-10 10:46:41

创建 PE 时,保留对它的引用:

// 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);

当您希望它停止时,告诉它停止(假设它已启动):(

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

PeriodicalExecuter#stop docs 此处。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文