开发者

Event triggering in server-side scripts

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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜