I have the following javascript code
$("#modal-yes-button").click(function (){
$("#myModal").modal('hide');
$(".modal-body").load('/url/that/returns/an/html/');
$("#myModal").modal('show');
});
and the following modal
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<h3>This is a question answer yes or later</h3>
</div>
<div class="modal-footer">
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Maybe Later</button>
<button id="modal-yes-button" class="btn btn-info" aria-hidden="true">Yes</button>
</div>
</div><!--modal-content-->
</div><!--modal-dialog-->
</div><!--myModal-->
I want the usere to press the yes button hide the modal(it says that bootstrap won't allow modal open when another one is open) load the new html content for the .modal-body and dipslay the modal dialog again. Only what i get is black screen(like when it shadows for the modal to appear) but the modal never appears. I played with it using the chrome dev tools and the modal appears normally
chrome dev-tools
modaldialog = $("#myModal");
modaldlgBody = $(".modal-body");
modaldlgBody.load('/url/that/returns/html/');
modaldialog.modal('show');
With the above commands the new new "body" is loaded normally. But if i try to load the dialog first and then press the yes button even when triggering the modal from the chrome dev-tools i get the same behavour, black screen. What could be wrong?
chrome dev-tools that giving the same black screen
modaldialog = $("#myModal");
modaldialog.modal('show');
#pressing yes gets me the same black screen.
First off, you should wait for the closing animation to finish before reopening your dialog.
You can listen to the
hidden.bs.modalevent :Now, this would pop back your modal each time you close it, even when clicking on the "dismiss" button. You want to listen to this event only once, when the user clicks on the "Yes" button. You can take advantage of the
jQuery.one()binder :fiddle
But I don't see a good reason to keep the very same dialog open - it includes a "Yes" button with specific logic, which would need to be changed after the load completes ...
You can serve a complete dialog, using
$.get, and simply display that :