我得到了这个 php 脚本,它生成需要 20 到 30 秒才能完成的报告。我想添加一个进度条,并且我的数据库中的进度已正确更新。
问题是,当主页加载报告时,我无法使用 jQuery 来 $.post
或 $.get
。
我可以运行 javascript,例如弹出一个窗口,显示“请稍候”并显示一个旋转的小图标,但 Firefox 拒绝在加载主页时发送 ajax post/get。
有办法解决这个问题吗?我尝试将其全部放入 iframe 中,但这不起作用。 (我正在使用 firebug 和 http live headers 监控流量。)
最佳答案
页面加载后,您可以在报告中加载 jQuery,例如:
$(document).ready(function() {
$('#someDiv').html('<strong>Loading...</strong>')
.load('report.html');
});
有关进度条,请查看 jQuery UI Progressbar 。也就是说,手册提出了这样的观点:
if the actual percent complete status cannot be calculated, an indeterminate progress bar (coming soon) or spinner animation is a better way to provide user feedback.
因此,如果是这种情况,我会推荐一个动画旋转图像或带有适当消息的此类图像,例如:
$(document).ready(function() {
$('#someDiv').html('<img src="images/spinner.gif"/><strong>This could take a while...</strong>')
.load('report.html');
});
关于jquery - 在加载主页时运行 ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1499532/