如何在 ajax 成功中打开引导模式
How to open bootstrap modal in ajax success
我想通过jquery打开bootstrap mod。我知道 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(resp){
$("#getCode").html(resp);
$("#getCodeModal").modal('show');
}
试试这个:
success: function(data) {
$("#getCode").html(data);
jQuery("#getCodeModal").modal('show');
}
这应该:)有效。
记下以下代码。
success: function(msg)
{
$("#getCodeModal").modal("show");
$("#getCode").html(msg).show();
}
当您包含库 jquery 两次时,就会发生这种情况。 检查一下,也许您将其包含在索引中,然后再次不必要地包含在部分页面中。
第一次切换模态后,您必须再次将其切换为"关闭"..并在成功功能上切换它,它将正常显示。例:
$('#Modal').modal('toggle) //this is the first time to toggle the modal
$('#Modal').modal('toggle) //this is the second time "to turn it off"
success:function(){
$('#Modal').modal('toggle) //this is the third time to "turn it on again"
}
相关文章:
- Ajax模式下的Jquery Select2 V4在IE9中不起作用
- 含义模式:'中止'在JS Ajax请求中
- 如何在模式框中显示ajax调用返回的数据
- 不确定我在PHP AJAX中使用的是什么开发模式
- 在单模式中断功能中使用Ajax渲染部分
- Twitter引导模式通过Ajax更改内容
- 为模式设置的值在通过 AJAX 成功函数设置时不显示
- 如何在 ajax 成功中打开引导模式
- 在ajax回调(safari)中调用bootstrap模式显示
- 尝试单击图像并打开模式ajax
- 在一个模式AjAX编码器中显示不同的Gallery
- 同步/异步AJAX函数的模式
- 允许select2jquery-ajax在标记模式下重复标记
- 简单模式ajax
- 简介.js与引导模式和AJAX
- AJAX 在调试模式下工作,但不是实时的
- 如何在通过 AJAX 提交后显示模式窗体
- 在引导模式 - AJAX 中显示 JSON 数据
- 引导模式AJAX调用未显示
- 引导模式ajax内容,动画加载