如何使加载图标出现,直到我的表用javascript生成
How to make a loading icon appear till my table is generated in javascript
我有一个UI,可以在浏览器中将csv文件转换为表。但是生成表格需要大约15秒的时间。我想在生成表格之前,显示一个加载图标而不是一个警告框。下面是我的代码。
$.getJSON(json_link, function (result) {
var th_main = "";
for (var e in result['fields']) {
th_main = th_main + '<th>' + e + '</th>';
}
var table_header = '<thead>' +
'<tr>' +
th_main +
'</tr>' +
'</thead>';
var body_main = "";
for (var i = 0; i < result['rows'].length; i++) {
var tr = "<tr>";
for (var ele in result['rows'][i]) {
tr = tr + '<td>' + result['rows'][i][ele] + '</td>';
}
var tr = tr + "</tr>";
body_main = body_main + tr;
}
var table_body = '<tbody>' + body_main + '</tbody>';
var table = "<table class='table table-bordered table-hover table-condensed table-striped'>" + table_header + table_body + "</table>";
alert("Loading...Please wait!");
$(".jumbotron").dialog("open")
.dialog({
height: 670,
title : data1,
width: 1130,
resizable: true,
open: function (type, data) {
$(this).parent().appendTo("form");
}
})
.dialogExtend({
"closable": true,
"titlebar": 'transparent',
"minimizable": true,
"minimizeLocation": "right",
"icons": {
"close": "ui-icon-circle-close",
"minimize": "ui-icon-circle-minus",
"maximize" : "ui-icon-circle-plus",
"restore": "ui-icon-circle-triangle-n"
}
});
$('.loading').show();
$.getJSON(json_link, function (result) {
// your code here
$('.loading').hide();
});
.loading{
position:fixed;
display:block;
width:100%;
height:100%;
background-color:rgba(255, 204, 204,.9);
top:0;
}
.loading img{
position:absolute;
left:50%;
top:50%;
margin-top:-18px;
}
<div class="loading">
<img src="http://www.ajaxload.info/images/exemples/21.gif"/>
</div>
此演示用于图像加载demo
你可以尝试一些类似的东西
$(".someSpinnerImage").show();
$.getJSON(json_link, function (result) {
// Do something with data
$(".someSpinnerImage").hide();
}
相关文章:
- 有没有一种方法可以生成Braintree令牌,而不必向我的服务器添加PHP脚本
- 如何在我的javascript生成列表中的
- 部分中放置更多超链接
- 为什么我的 ajax 调用没有生成,因为我包含 ajax 的 js 文件包含在 iframe 中
- 我如何生成一个警告/弹出窗口,说明在用户点击之前避免点击浏览器的后退按钮
- 什么是检查随机字符串I've生成了has't是我以前生成的
- 为什么我的脚本不使用keyup生成新行
- 我将如何能够使元素为我的网站建设者生成代码
- 为什么内部 html 的 src 属性无法识别我的动态生成的变量
- 我的 JavaScript 没有正确生成 HTML
- 将 grunt-connect-proxy 添加到我的 Yeoman 生成的 gruntfile.js
- 脚本在我的<头>标签中自动生成
- 为什么我的 PDF 生成过程会锁定我的站点中的其他 ajax 进程
- 鲍尔安装不在我的项目中生成库
- 如果我的响应在运行时更改结构,如何生成动态页面
- 如何将Grunt生成的文件git添加到我的Github存储库中
- 我的JavaScript代码无法读取PHP代码生成的JSON.出了什么问题
- jQuery无法'connect'与我的服务器生成的网页上的元素
- 在我的网站上用生成的jquery跟踪链接点击,在其他人的网站上使用
- 我的html标记应该在客户端生成吗
- 我的JavaScript生成的表单字段/数据在提交时不会与表单的其余部分一起发送