php - 用户接受好友请求的通知
问题描述
我正在制作一个带有友谊系统的网站。“朋友”表如下所示:
id | id1(this is sender) | id2 | accepted | notification
id1 是发送请求的人。当 id2 接受它时,接受并且通知将为 1。通知意味着具有 id1 的用户将看到一个通知:用户(具有 id2)接受了您的请求。当具有 id1 的用户单击该通知时,我想将通知更改为 0。我通过制作带有动作“ something.php
”的表格来完成所有动作。我认为有一种更好的方法来更改一列(按行),而不是像我一样做。
我应该使用什么方法?有哪些方法可行?
解决方案
您应该考虑使用 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
}
});
});
推荐阅读
- c++ - 制作全局变量的编译时寄存器并节省RAM
- mutual-information - 互信息计算
- java - Spring bean 依赖于多个配置文件
- java - Java中的PUT请求
- reactjs - 设置自定义羽毛笔印迹覆盖格式方法的属性不会触发羽毛笔编辑器中的 onChange 事件
- xslt-2.0 - 需要在'dyn'下的每个嵌套'dn'元素中添加带有颜色名称的@color属性
- symfony - Twilio 消息未收到传入消息回调
- mongodb - 如何添加mongodb每个文档数组对象?
- reactjs - 为 React 径向图表段添加圆边
- typescript - 自定义字体在发布模式下丢失