devcoder devcoder - 1 year ago 286
Javascript Question

How to implement a loading indicator for a bootstrap modal waiting for AJAX to fetch data from the server?

I have a bootstrap modal which is launched from a link. For about 3 seconds it just sits there blank, while the AJAX query fetches the data from the database. How can I implement some sort of a loading indicator ? Does twitter bootstrap provide this functionality by default ?

EDIT: JS code for modal

<script type="text/javascript">
$('div.divBox a').click(function(){
var vendor = $(this).text();
$('#myModal').on('show', function(){
type: "GET",
url: "ip.php",
data: "id=" + vendor,
success: function(html){
$(".modal-header h3").html(vendor);
"sDom": "T<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
"aaSorting":[[0, "desc"]],
"iDisplayLength": 10,
"oTableTools": {
"sSwfPath": "swf/copy_csv_xls_pdf.swf",
"aButtons": ["csv", "pdf"]
$('#myModal').on('hide', function () {

Answer Source

I'm guessing you're using jQuery.get or some other jQuery ajax function to load the modal. You can show the indicator before the ajax call, and hide it when the ajax completes. Something like

$('#someModal').get(anUrl, someData, function() { $('#indicator').hide(); });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download