jquery - 在加载主页时运行 ajax

标签 jquery ajax firefox loading

我得到了这个 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/

相关文章:

javascript - 如何将参数传递给回调函数而不执行它

jquery - 闪烁容器的背景橙色(就像直接导航到答案时所做的那样)

javascript - 如何在 jquery 和 ajax 中的 window.location.href 之后显示/显示 div

jquery - 如何使用按钮加载更多网格对象

php - AJAX 调用后 session 变量未更新

javascript - jQuery CSS Hooks 很慢。可以禁用或修复?

javascript - 如何在窗口关闭时从JS弹出窗口中获取数据

javascript - 为什么 jQuery 动画在不是事件选项卡时会变得困惑?

html - 网站在 Safari 中有效,但在 Firefox 中无效

html - 当我从本地文件和 Codepen 打开相同的代码时,它看起来不同。为什么会发生这种情况?