I have a Bootstrap modal dialog which contains a form. The modal dialog contains a submit and a cancel button. Now on submit button click the form is submitted
The listed answers won't work if the results of the AJAX form submit affects the HTML outside the scope of the modal before the modal finishes closing. In my case, the result was a grayed out (fade) screen where I could see the page update, but could not interact with any of the page elements.
My solution:
$(document).on("click", "#send-email-submit-button", function(e){
$('#send-new-email-modal').modal('hide')
});
$(document).on("submit", "#send-email-form", function(e){
e.preventDefault();
var querystring = $(this).serialize();
$.ajax({
type: "POST",
url: "sendEmailMessage",
data : querystring,
success : function(response) {
$('#send-new-email-modal').on('hidden.bs.modal', function () {
$('#contacts-render-target').html(response);
}
});
return false;
});
Note: My modal form was inside a parent div that was already rendered via AJAX, thus the need to anchor the event listener to document.