服务器端脚本中的事件触发

发布于 2024-08-26 09:00:48 字数 150 浏览 5 评论 0原文

那么,当你的问题得到答案时。或者您获得了新徽章,事件被触发。或者当您在论坛中收到新的 PM 时,它也会通过提醒消息让您知道。

当您在此事件后首次进入网站时,您会看到一条消息,表明您的帐户发生了问题。

这是如何实施的?脚本如何知道他们有新的东西要向您展示?

In SO, when your question got answer. or you got new badge, event is triggered. Or when you got new PM in forum, it also lets you know by alerting message.

You see message that something happened with your account when you enter site for first time after this event.

How is this implemented? How do scripts know, that they have something new to show you?

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

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

发布评论

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

评论(3

鹿! 2024-09-02 09:00:48

您正在寻找的编程技术称为 Comet。维基百科的链接描述了它的一些实现,但最简单的方法是创建一个具有较长超时时间的 XMLHttpRequest,并且仅在更改时返回数据。

The programming technique you are looking for is called Comet. The link to wikipedia describes some implementations of that, but the easiest way is to make an XMLHttpRequest with a long timeout and only return data on change.

少年亿悲伤 2024-09-02 09:00:48

作为对您上一条评论的答复
有多种技术可以将事件标记为“新”事件。它可以是数据库表中的另一个布尔类型字段:告知事件是否向用户显示。或者 - 最简单的一个 - 只是在会话中记录最后一次用户访问的时间,然后将所有即将发生的事件的时间与其进行比较。

As an answer to your last comment
There are several tecniques to mark events as a 'new'. It can be another field in the database table, of boolean type: telling if event was shown to user or not. Or - easiest one - just a time of last user's visit being recorded in the session, and then al upcoming event's time being compared with it.

清风不识月 2024-09-02 09:00:48

当另一个人对您的答案或问题进行投票等操作时,就会发生该事件。这是在服务器端记录的。

当您登录网站时,可以通过在数据库中查找这些记录来确定在您离开时发生了某些事件。

当您访问该站点时,该页面可以定期轮询服务器以了解更改。所以它实际上并不是触发事件的服务器。

The event happens when another person does something like vote on your answer or question. This is recorded on the server side.

When you log on to the site the fact that some events occured while you were away can be determined from looking up the database for these records.

While you are on the site it is possible for the page to periodically poll the server for changes. So its not really the server that the event is triggered on.

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