我有一个通过链接启动的Bootstrap模态框。大约3秒钟它只是空白,而AJAX查询从数据库获取数据。如何实现某种类型的加载指示器?Twitter Bootstrap是否默认提供此功能?
编辑:模态框的JS代码
<script type="text/javascript">
$('#myModal').modal('hide');
$('div.divBox a').click(function(){
var vendor = $(this).text();
$('#myModal').off('show');
$('#myModal').on('show', function(){
$.ajax({
type: "GET",
url: "ip.php",
data: "id=" + vendor,
success: function(html){
$("#modal-body").html(html);
$(".modal-header h3").html(vendor);
$('.countstable1').dataTable({
"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 () {
$("#modal-body").empty();
});
</script>
ajaxStart()
和ajaxStop()
会是更好的解决方案,因为它们仅在每个AJAX批处理中触发一次:https://dev59.com/nG865IYBdhLWcg3wl_s3 - SharpC