问题 如何在ajax成功中打开bootstrap模式


我想通过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">&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>

在控制台中出错:模态不是函数。


5361
2018-03-08 08:34


起源

会发生什么?控制台有些错误? - Anatoliy Arkhipov
尝试将开口支架放在一行中 success: function(msg) - knitevision
你导入了吗? bootstrap.js? - Anatoliy Arkhipov
是。我确定是进口的。它通过data-attribute显示。 - user254153
我解决了这个错误。是在bootstrap.js之后导入了jquery库。 - user254153


答案:


试试这个

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

10
2018-03-08 08:39



只要 $("#getCodeModal").modal('show'); 在成功功能中需要。 @Shakil放置时不会显示模型中的任何内容 $("#getCode").html(resp); 之前 - Nwawel A Iroume
这也是我正在寻找的正确答案。谢谢。 - ÖMER TAŞCI


试试这个:

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

这应该工作:)。


3
2018-03-08 08:42



从上面复制 - Ashwani Shukla


当你包含两次库jquery时会发生这种情况。检查一下,也许你将它包含在你的索引中,然后在你的部分页面中再次不必要。


0
2017-12-11 19:51