【发布时间】:2015-05-09 13:53:38
【问题描述】:
我想通过 jquery 打开引导模式。我知道 ajax 运行成功,因为它会引发警报。但无法打开模态。这些是我的代码。
$.ajax({
type: "POST",
url: "<?php echo base_url() . 'index.php/application/requestCode'; ?>",
data: {
'apiName': apiName,
'api': api,
'hotel': hotel,
'payment':payment,
'template': template
},
success: function(msg)
{
$("#getCodeModal").modal("toggle");
$("#getCode").html(msg);
}
});
我的模态 HTML 是:
<!-- Modal -->
<div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> API CODE </h4>
</div>
<div class="modal-body" id="getCode" style="overflow-x: scroll;">
//ajax success content here.
</div>
</div>
</div>
</div>
控制台出错:模态不是函数。
【问题讨论】:
-
然后会发生什么?控制台中的一些错误?
-
尝试将左括号与
success: function(msg)放在一行中 -
你导入
bootstrap.js了吗? -
是的。确定我进口了它。它通过数据属性显示。
-
我解决了这个错误。就是在 bootstrap.js 之后导入了 jquery 库。
标签: javascript jquery css ajax twitter-bootstrap