Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
jQuery AJAX form submit with Twitter Bootstrap modal
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
success: function(data, status) {
<!-- Bootstrap trigger to open modal -->
<a data-toggle="modal" href="#rating-modal">Write a Review</a>
<div class="hide fade modal" id="rating-modal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2>Your Review</h2>
<div class="modal-body">
<!-- The async form to send and replace the modals content with its response -->
<form class="form-horizontal well" data-async data-target="#rating-modal" action="/some-endpoint" method="POST">
<!-- form content -->
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
Copy link

frozenade commented Sep 24, 2016

Hi, how to add loading indicator while saving?

Copy link

iammichaelgarcia commented Jan 13, 2018

@frozenade Put a div with id name of your choice and first line of the function add. In my example below I named the div id="processing"


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment