处理大文件时的 jQuery throbber
在我的 Web 应用程序上,用户可以生成一个 CVS 文件,有时该文件可能会达到 10+ Mb。该报告显然需要一些时间才能生成。我想在生成报告时为用户显示一个 throbber,一旦提示他们保存/运行,我希望隐藏 throbber。这可能吗?
On my web app the user can generate a CVS file that can get pretty large 10+ Mb sometimes. The report obviously can take some time to generate. I want to display a throbber for the user while the report is being generated, once they are prompted to save/run I want the throbber to hide. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,实际上不可能检测文件何时到达以及用户何时保存它。您几乎陷入困境,只是更新您的 throbber 并在他们准备好继续时提供继续链接。
如果这是可能的,那么当您完成文件的登陆页面时,下载网站将使用它自动将您转发到下载列表。
No, it's not really possible to detect when the file arrives and the user saves it. You're pretty much stuck just updating your throbber and offering a continue link when they're ready to continue.
If this was possible then the download sites would use it to auto-forward you to the download list when you're finished at the file's landing page.
是的,JavaScript 中的繁重操作通常会被分成多个块,然后从 setInterval 中调用。超时可以防止页面冻结。
Yes, typically heavy operations in JavaScript are split into chunks and then called from a setInterval. The timeout keeps the page from freezing up.
我猜您正在发布一些数据,在服务器上生成 CSV,设置内容类型并等待浏览器的保存对话框出现。正确的?
那样的话,我想你会失望的。我花了相当多的时间试图找到适合这种情况的事件,但我无法弄清楚。我最终不得不做一些复杂的事情,比如使用 XHR 来轮询文件创建的状态。一旦得到我想要的响应,我就隐藏了 throbber 并请求 CSV。
更清楚地说:
I'm guessing that you are posting some data, generating the CSV on the server, setting the content-type and waiting for the browser's save dialog to appear. Correct?
In that case, I think you will be disappointed. I spend quite some time trying to find events that would fire for this exact scenario and I couldn't figure it out. I finally had to do something convoluted like use XHR to poll the status of the file creation. Once I got the response I wanted, I hid the throbber and requested the CSV.
To be clearer: