Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
推送器通知上的jQuery Div通知警报语法_Jquery_Html_Pusher - Fatal编程技术网

推送器通知上的jQuery Div通知警报语法

推送器通知上的jQuery Div通知警报语法,jquery,html,pusher,Jquery,Html,Pusher,我通过pusher将事件推送到以下代码: 我没有从alertDivNotification获取预期的html <!-- output --> <div class="alert alert-danger alert-server" role="alert">Hello</div> <!-- expected --> <div class="alert alert-danger alert-server" role="alert">

我通过pusher将事件推送到以下代码: 我没有从alertDivNotification获取预期的html

<!-- output -->
<div class="alert alert-danger alert-server" role="alert">Hello</div>

<!-- expected -->
<div class="alert alert-danger alert-server" role="alert">
  <button type="button" class="close" data-dismiss="alert">×</button>
  <strong>Moving Servers</strong> Hello
</div>

你好
×
移动服务器您好
var-channel=pusher.subscribe('my-channel');
channel.bind('my-event',函数(数据){
var alertDivNotification=$(“×移动服务器消息”);
html(data.message);
$(“#alertDivContainer”).prepend(alertDivNotification);
});
问题在于:

var alertDivNotification = $('<div class="alert alert-danger alert-server" role="alert"><button type="button" class="close" data-dismiss="alert">×</button><strong>Moving Servers</strong> message</div>');
alertDivNotification.html(data.message);
(编辑)如果要将
数据.通知\u标题添加到推送器事件并显示该事件,可以:

var alertDivNotification = $('<div class="alert alert-danger alert-server" role="alert"><button type="button" class="close" data-dismiss="alert">×</button></div>');
alertDivNotification.append($('<strong></strong>').append(document.createTextNode(data.notification_title)));
alertDivNotification.append(document.createTextNode(data.message));
var-alertDivNotification=$('×');
alertDivNotification.append($('').append(document.createTextNode(data.notification_title));
append(document.createTextNode(data.message));

会发生什么情况?您是否在事件处理程序中收到Pusher事件?您可以通过在
var-alertDivNotification=…
上方添加日志行进行检查。您还可以添加
pusher.logToConsole=true
并向我们显示您的日志。我还认为您的
.html(…)
将删除div中的
。这可能不是您想要的。@jameshfisher是的,推送事件被正确触发,html div缺少元素。您如何在之间添加(数据.通知\u标题){{data.notification_title}?@dflow我用一个建议编辑了我的答案(未经测试)。希望对你有所帮助!
var alertDivNotification = $('<div class="alert alert-danger alert-server" role="alert"><button type="button" class="close" data-dismiss="alert">×</button></div>');
alertDivNotification.append($('<strong></strong>').append(document.createTextNode(data.notification_title)));
alertDivNotification.append(document.createTextNode(data.message));