user9868666
user9868666

Reputation:

Bootstrap modal not close after submit data through jquery ajax method

i wanna put data into database through bootstrap modal with ajax. But after submit data button on modal the modal not close automatically. How i can fix this.

Here is code of Bootstrap modal

 <!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

This is ajax code

  <script type="text/javascript">


   ***
          SOme Code Here
    ****


          $.ajax({
            type: 'GET',
            url  : "YOu URL",
            data: {},
             success:  function(feedback){
                $('#feedback').html(feedback);

              }
            });
        });
     });
    </script> 

Upvotes: 0

Views: 1012

Answers (2)

Anirudh Prabhu
Anirudh Prabhu

Reputation: 53

The syntax for modal closing seems fine. But I'm not sure if you are targetting right modal element. See if the target id on which you are triggering the modal close code is right. Hope it solves your problem.

Upvotes: 0

Kes
Kes

Reputation: 498

In your success method, you call to close the model by using

$('#yourModal').modal('hide');

Btw, it is advisable to do a http POST rather than a GET for submissions.

Upvotes: 2

Related Questions