0

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> 
  • Possible duplicate of [Close Bootstrap Modal](https://stackoverflow.com/questions/16493280/close-bootstrap-modal) – Nisarg Aug 29 '18 at 17:53

2 Answers2

2

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.

Kes
  • 448
  • 6
  • 20
  • 1
    Please dun call me dear as a start... Perhaps you might want to include the full HTML code for your modal where element with "add_category" is. Based on bootstrap site, you are missing 2 div wrapper for ur "modal-content" div – Kes Aug 30 '18 at 01:57
0

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.