Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open bootstrap modal in ajax success

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);
    }
});

And my modal HTML is:

 <!-- 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.

like image 859
user254153 Avatar asked Mar 08 '15 08:03

user254153


1 Answers

try with this

success: function(resp){
    $("#getCode").html(resp);
    $("#getCodeModal").modal('show');
}
like image 50
Abdullah Al Shakib Avatar answered Sep 23 '22 19:09

Abdullah Al Shakib