Javascript 如何在ajax成功中打开引导模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28924551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open bootstrap modal in ajax success
提问by user254153
I want to open bootstrap modal through jquery. I know ajax in running to success as it throws alerts. But cannot open modal. These are my code.
我想通过 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);
}
});
And my modal HTML is:
我的模态 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>
In error in console: modal is not a function.
控制台出错:模态不是函数。
回答by Abdullah Al Shakib
try with this
试试这个
success: function(resp){
$("#getCode").html(resp);
$("#getCodeModal").modal('show');
}
回答by Parham Hojjat
Try this one:
试试这个:
success: function(data) {
$("#getCode").html(data);
jQuery("#getCodeModal").modal('show');
}
This should work :).
这应该有效:)。
回答by Dan
this happen when you include library jquery twice. check for that, maybe you include it in your index and then again unnecessarily in you partial page.
当您两次包含库 jquery 时会发生这种情况。检查一下,也许你将它包含在你的索引中,然后又不必要地在你的部分页面中。
回答by Jitender Sharma
Write down the following code.
写下以下代码。
success: function(msg)
{
$("#getCodeModal").modal("show");
$("#getCode").html(msg).show();
}

