我想通过jquery打开bootstrap模式。我知道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>
控制台出错:模态不是函数。
答案 0 :(得分:12)
试试这个
success: function(resp){
$("#getCode").html(resp);
$("#getCodeModal").modal('show');
}
答案 1 :(得分:5)
试试这个:
success: function(data) {
$("#getCode").html(data);
jQuery("#getCodeModal").modal('show');
}
这应该有效:)。
答案 2 :(得分:0)
当您将库jquery包括两次时会发生这种情况。检查一下,也许你将它包含在你的索引中,然后在你的部分页面中再次包含它。
答案 3 :(得分:0)
success: function(msg)
{
$("#getCodeModal").modal("show");
$("#getCode").html(msg).show();
}