I am working for a small project.In this project I have a modal which is called with ajax response after clicking.But the modal is not closing.Any ideas about how I can sove this bugs.Thanks in advance.
My demo code:
<button class="open-modal">Open modal</button>
<div
class="modal fade reactor_modal "
id="modal"
tabindex="-1"
role="dialog"
aria-labelledby="modalTitle"
aria-hidden="true"
>
</div>
JS code
$('.open-modal').click(function(post_id) {
var $modal = $('.modal');
$.ajax({
url: 'get_react_user.php',
type: get,
cache: false,
success: function(data) {
console.log(data);
$($modal).modal("show");
$($modal).html(data)
console.log($modal);
}
})
})
$(document).on('click','.close-modal',function()
$('.modal').modal('hide')
})
PHP code
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalTitle">Reactions</h5>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<h1>Working</h1>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary close-modal" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
2
Answers
Try adding class="btn btn-default" to the close button.
Also try looking at this URL example, hope that It will help.
https://www.tutorialrepublic.com/codelab.php?topic=faq&file=jquery-close-bootstrap-modal
Maybe something like this [ demo jsfiddle : https://jsfiddle.net/8u19pgrn/ ]