推送器通知上的jQuery Div通知警报语法
我通过pusher将事件推送到以下代码: 我没有从alertDivNotification获取预期的html推送器通知上的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">
<!-- 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));