Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close Bootstrap's modal with AJAX

I use the modal of Twitter's Bootstrap. You can close the modal, by clicking on a button or something different with the tag data-dismiss="modal". I would like to process my form in the modal with AJAX (by clicking on a submit button) and then close the modal. So how do close this modal in AJAX? Or is that not possible?

(sorry for my bad English...)

like image 260
Jon Avatar asked Oct 25 '13 18:10

Jon


People also ask

How do I stop pop ups in Ajax?

To close bootstrap modal you can pass 'hide' as option to modal method as follows. $('#CompanyProfile'). modal('hide'); Use this code inside ajax success.

How do I close a bootstrap modal?

Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.

How do I turn off modal dialog?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal.

How do I stop the modal pop up in HTML?

To close a modal, add the w3-button class to an element together with an onclick attribute that points to the id of the modal (id01). You can also close it by clicking outside of the modal (see example below).


2 Answers

If you read further down the documentation:

$('#myModal').modal('hide')

Just get the ID of the modal, and replace myModal with it. Then place it in the AJAX success handler and there you have it.

like image 193
Joseph Avatar answered Oct 08 '22 13:10

Joseph


You can use this script to close the modal

<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">
    <i class = "icons-office-52"></i> 
</button> 
    $("#close_btn").trigger("click");

or

$('#my_model').modal('hide');
like image 39
David Arul Avatar answered Oct 08 '22 13:10

David Arul