javascript - 如何清除推送器的警报消息?
问题描述
我正在使用 PUSHER 进入我的网站以获取通知。我成功添加了代码及其工作。但问题是当警报被触发时,我正在接收消息,但这不是我想要的。
我从 Javascript alert() 收到这条消息;
{"message":"A new appointment arrived"}
来自推送者的警报消息 我的代码是
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
document.getElementById('audio').play();
alert(JSON.stringify(data));
$.ajax({url: "notification", success: function(result){
$("#notification").html(result);
}})
});
这就是我得到这个的地方。
$data['message'] = 'A new appointment arrived';
$pusher->trigger('my-channel', 'my-event', $data);
我收到的消息来自
JSON.stringify(data)
我的问题是,有没有办法可以删除除A new appointment arrived
警报消息之外的所有内容?提前致谢。我是初学者,对 Javascript 知之甚少。
解决方案
删除行:alert(JSON.stringify(data));
在您的 JS 代码中。这会使用从您的事件收到的消息触发警报。
您可以在此处阅读有关alert()
方法的更多信息:https ://developer.mozilla.org/en-US/docs/Web/API/Window/alert
推荐阅读
- spring-cloud-dataflow - spring-cloud 数据流外壳没有响应
- sql - 月份序列和完整月份名称 - SQL Server
- sql - 在 Db2 命令行处理器 CLP 中使用 SQL LIKE 谓词
- gradle - gradle本地jar依赖不起作用
- html - 下拉菜单问题(位置)
- sql - SQL 查询左外连接到当前查询
- php - Laravel 应用程序尝试使用另一个数据库对用户进行身份验证
- sql - 如何重写查询中的一些值?- PostgreSQL
- php - Laravel Homestead 数据库无法通过 PHPstorm 和迁移时留下错误消息
- c++ - 检查智能指针是否为空的模板函数