如何在Ajax成功中打开Bootstrap模态 [英] How to open bootstrap modal in ajax success

查看:66
本文介绍了如何在Ajax成功中打开Bootstrap模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过jquery打开引导模态.我知道ajax会引发警报,因此可以成功运行.但是不能打开模式.这些是我的代码.

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.

$.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">&times;</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.

推荐答案

尝试与此

success: function(resp){
    $("#getCode").html(resp);
    $("#getCodeModal").modal('show');
}

这篇关于如何在Ajax成功中打开Bootstrap模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆