How can I get the results of a form post to display in a modal window in Bootstrap 3?
I have a list of items, and each item has an "edit" button. When an edit button is clicked, I need to post to a form and trigger a modal pop-up with the response. I'm trying to do this using jQuery's .ajax()
function, and I'm not sure if it's the best approach:
$(".editForm").submit(function() {
$.ajax({
type : "POST",
cache : false,
url : "./edit_form.php",
data : $(this).serializeArray(),
success: function() {
## How do I get the response to show up in a Bootstrap 3 modal? ##
}
});
return false;
});
But, I'm getting stuck when it's time to parse the result of the form post. How can I get that to appear in a modal pop-up in Bootstrap 3? The Bootstrap docs talk about triggering a modal from an anchor link with <a data-toggle="modal" href="remote.html" data-target="#modal">Click me</a>
, but how would you trigger it with a form post?
Maybe I'm thinking about it backwards, or over-complicating it. Perhaps I should open the modal first, then submit the .ajax()
form post, then update the <div>
with the result. I'm used to using Fancybox, and am switching to Bootstrap for all modals.
Thanks!