【发布时间】:2019-11-06 00:25:28
【问题描述】:
我想通过 ajax 调用设置带有 html 的 Bootstrap4 弹出框的内容。
有很多适用于 Bootstrap 3 的解决方案,但找不到适用于 Bootstrap 版本 4 的解决方案。
这是我的 HTML:
<button type="button"
id="AlertsBellButton"
class="btn btn-lg btn-danger"
data-toggle="popover"
data-placement="bottom"
data-trigger="focus"
title="Alerts"
data-html="true"
data-content="Loading...">
<i class="fal fa-bell"></i>
</button>
还有我的 Javascript:
$('#AlertsBellButton').on('show.bs.popover', function () {
$.ajax({
url: '/Alert/GetAlertsForBell/',
type: 'get',
cache: false,
success: function (data) {
$('#AlertsBellButton').attr('data-content', data);
}
});
});
设置 data-content 属性显然应该可以解决问题;第一次点击铃铛,第一次ajax调用完成后,内容显示“Loading...”,第二次点击,显示正确数据。
我也尝试在成功处理程序中使用 jQuery 定位 div,但这不起作用,因为 Bootstrap4 尚未将弹出框添加到 DOM。
【问题讨论】:
标签: jquery bootstrap-4 popover