首页 > 解决方案 > 用户接受好友请求的通知

问题描述

我正在制作一个带有友谊系统的网站。“朋友”表如下所示:

id | id1(this is sender) | id2 | accepted | notification

id1 是发送请求的人。当 id2 接受它时,接受并且通知将为 1。通知意味着具有 id1 的用户将看到一个通知:用户(具有 id2)接受了您的请求。当具有 id1 的用户单击该通知时,我想将通知更改为 0。我通过制作带有动作“ something.php”的表格来完成所有动作。我认为有一种更好的方法来更改一列(按行),而不是像我一样做。

我应该使用什么方法?有哪些方法可行?

标签: phphtml

解决方案


您应该考虑使用 AJAX 在后台调用您的“something.php”。

使用表单执行此操作意味着当用户看到通知时将重新加载整个页面。使用 AJAX 不会发生这种情况。

请参阅以下链接: https ://developer.mozilla.org/en-US/docs/Web/Guide/AJAX

使用 jQuery 它应该看起来像这样

$('#notification').onClick( function(){
    $.ajax({
        type: "post",
        data: {},
        url: "something.php",

        success: function(){
             //do something like clearing notification on frontend
        }
    });
});

推荐阅读