首页 > 解决方案 > 如何清除推送器的警报消息?

问题描述

我正在使用 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 知之甚少。

标签: javascriptphpjsonalertpusher

解决方案


删除行:alert(JSON.stringify(data));在您的 JS 代码中。这会使用从您的事件收到的消息触发警报。

您可以在此处阅读有关alert()方法的更多信息:https ://developer.mozilla.org/en-US/docs/Web/API/Window/alert


推荐阅读