2

当用户单击收件箱中的链接时,我想将与该链接相关的消息标记为seen.

SO也有这个功能,
如果有人回复我的帖子,SO会显示我的帖子发生了什么事。
单击收件箱消息并访问帖子后,SO不再显示通知标记。

我想每次用户访问任何问题页面时测试问题的访问用户是否都有收件箱消息太昂贵了。
我想知道是否可以clicking-link在收件箱页面中捕获,以便我可以在后台发送 ajax 请求来标记消息as seen

希望我的问题很清楚。

4

2 回答 2

1

为您单击的每条消息添加自定义数据属性。我不确定您如何显示消息,但对于本示例,我们将使用跨度:

<span class="message">Some Message</span>

和 JS:

$(".message").click(function() {
    $(this).data("visited", true);
});

然后您可以检查跨度以查看它们是否已被访问。如果您仍想进行 AJAX 调用,您也可以简单地在单击处理程序中添加一个 AJAX 事件。

于 2013-06-28T03:41:06.167 回答
0

我假设您的消息表上有某种“状态”字段来区分“已读”和“未读”。

如果您询问如何有效地将未读邮件的数量存储在收件箱中,而无需在每次页面加载时运行查询,这可以通过设置 $_SESSION 变量轻松完成:

$_SESSION['unread_messages'] = 2;

After this variable is set, you can periodically check (every 5 minutes or so) to keep this up to date within a reasonable window. When a message is clicked and read, you will subtract 1 from this value or re-query the number of unread messages.

If you are asking about how to update the database and UI, there are 2 main ways you would go about doing this. It will depend on what currently happens in your script when a user clicks on a message. Do you make an AJAX request to load the message, or does the link take the user to a different page?

If you make an AJAX request when a message is clicked, simply have the script that is called in the AJAX request also mark the message as read (in the database), and use JavaScript to make any UI updates to the current page (such as removing bold text on the message that was clicked).

If clicking on a message redirects to a different page where the entire message is displayed, you can mark the message as read in the database when that page loads.

于 2013-06-28T03:52:45.060 回答