如何清除推送器的警报消息?
How to clean alert message from pusher?
我正在使用 PUSHER 进入我的站点以获取通知。
我成功地添加了代码及其工作。
但问题是当警报被触发时,我收到了消息,但它不是我要找的。
我从 Javascript alert();
收到这条消息
{"message":"A new appointment arrived"}
alert message from pusher
我的代码是
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.
了解甚少
删除您的 JS 代码中的行:alert(JSON.stringify(data));
。这会使用从您的事件收到的消息触发警报。
您可以在此处阅读有关 alert()
方法的更多信息:https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
如果我没有正确理解你的问题,那么你要问的是如何更改
警报中显示的输出
{"message":"A new appointment arrived"}
到 A new appointment arrived
。是吗?
JSON.stringify()
所做的是将 JavaScript 对象转换为 JSON 格式的文本字符串。由于您实际上对该对象不感兴趣,只对它包含的消息感兴趣,因此实际上没有必要在此处使用 JSON.stringify
。假设您收到的数据始终具有格式
{ message: "Some type of message" }
你可以只写 alert(data.message)
(或者 alert(data["message"])
如果你不喜欢 JavaScript 点符号)。
我正在使用 PUSHER 进入我的站点以获取通知。 我成功地添加了代码及其工作。 但问题是当警报被触发时,我收到了消息,但它不是我要找的。
我从 Javascript alert();
收到这条消息{"message":"A new appointment arrived"}
alert message from pusher 我的代码是
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.
删除您的 JS 代码中的行:alert(JSON.stringify(data));
。这会使用从您的事件收到的消息触发警报。
您可以在此处阅读有关 alert()
方法的更多信息:https://developer.mozilla.org/en-US/docs/Web/API/Window/alert
如果我没有正确理解你的问题,那么你要问的是如何更改
警报中显示的输出{"message":"A new appointment arrived"}
到 A new appointment arrived
。是吗?
JSON.stringify()
所做的是将 JavaScript 对象转换为 JSON 格式的文本字符串。由于您实际上对该对象不感兴趣,只对它包含的消息感兴趣,因此实际上没有必要在此处使用 JSON.stringify
。假设您收到的数据始终具有格式
{ message: "Some type of message" }
你可以只写 alert(data.message)
(或者 alert(data["message"])
如果你不喜欢 JavaScript 点符号)。