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

use*_*153 13 javascript css ajax jquery twitter-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);
    }
});
Run Code Online (Sandbox Code Playgroud)

我的模态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>
Run Code Online (Sandbox Code Playgroud)

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

Abd*_*kib 14

尝试这个

success: function(resp){
    $("#getCode").html(resp);
    $("#getCodeModal").modal('show');
}
Run Code Online (Sandbox Code Playgroud)


小智 6

试试这个:

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

这应该工作:).