在加载主页时运行 ajax
我得到了这个 php 脚本,它生成需要 20 到 30 秒才能完成的报告。我想添加一个进度条,并且我的数据库中的进度已正确更新。
问题是,当主页加载报告时,我无法使用 jQuery 来 $.post
或 $.get
。
我可以运行 javascript,比如弹出一个窗口,显示“请稍候”并显示一个旋转的小图标,但 Firefox 拒绝在加载主页时发送 ajax post/get。
有什么办法解决这个问题吗?我尝试将其全部放入 iframe 中,但这不起作用。 (我正在使用 firebug 和 http live headers 监控流量。)
I got this php script that generates reports that take 20 to 30 seconds to complete. I would like to add a progress bar, and I have the progress updating in my DB correctly.
The problem is that I can't use jQuery to $.post
or $.get
while the main page is sitting there loading the report.
I can run javascript, like popup a window that says "please wait" and show a little spinning icon, but firefox refuses to send ajax post/get while the main page is loading.
Any way around this? I tried throwing it all in an iframe but that didn't work ether. (I'm monitoring the traffic using firebug and http live headers.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
页面加载后,您可以在报告中加载 jQuery,例如:
对于进度条,请查看 jQuery UI 进度条。也就是说,该手册提出了这样的观点:
因此,如果是这种情况,我会推荐一个动画旋转图像或带有适当消息的此类图像,例如:
You can have jQuery load in the report once your page has loaded, for example:
For a progress bar, check out jQuery UI Progressbar. That said, the manual makes this sound point:
so if that's the case I would recommend an animated spinner image or such with an appropriate message, for example:
您可能需要考虑 elementReady。如果您确保在开始处理耗时的报告之前加载 jquery 脚本并写出页面的一部分,您可以使用 elementReady 来启动某种通知。无需等待整个文档准备就绪。
我不确定这是否适用于 ui 进度条,但我已将其与 Thickbox 一起使用,以灰显并阻止屏幕输入,直到页面完全加载并且 Thickbox throbber .gif 作为一项活动运行得足够好指标。
You might want to consider elementReady. If you make sure your jquery script loads and a portion of your page are written out before the time consuming report begins to process you can use elementReady to kick off some kind of notification. There is no need to wait for the entire document to be ready.
I'm not sure if this will work with the ui progress bar, but I have used it with thickbox to grey-out and block input to the screen until the page has completely loaded and the thickbox throbber .gif works well enough as an activity indicator.
添加AJAX页面加载动画效果:
第 1 步:添加 jQuery 库
第 2 步:添加一些 CSS 以提供炫酷的外观(可选)
第 3 步:添加以下 jQuery
第 4 步:最后,在任意位置添加 html 代码。
To add AJAX page loading animation effect:
Step 1: Add jQuery Library
Step 2: Add some CSS to give cool appearance (optional)
Step 3: Add following jQuery
Step 4: finally, Add html code, wherever you want.