使用进度栏轮询文件上传服务器
这与询问如何上传文件和显示进度条的问题不同。我对基础知识的理解是:
- 我们有一个表单,将给定的输入文件发布到给定的 url。
- 单击提交按钮后,我们设置每秒运行一次 Javascript 方法的时间间隔,该方法使用 AJAX 轮询服务器以获取此下载的状态。
对我来说唯一的困境是我尝试了这种方法,但是当我查看 FireBug 控制台时,我可以看到所有这些 jQuery AJAX 调用。我看过其他人的实现,你在 FireBug > 中看不到任何内容网> XHR。
有谁知道这是如何实现的?
任何建议将不胜感激。
干杯, Mosh
PS:只是强调一下,我对使用 Flash 进行此操作不感兴趣。
This is not a duplicate of those questions that ask how to upload a file and display a progress bar. My understanding of the basics is:
- We have a form that posts the given input file to the given url.
- As soon as the submit button is clicked, we set interval to run a Javascript method every second, which uses AJAX to poll the server to get the status of this download.
The only dilemma for me here is that I tried this method, but when I look at FireBug console, I can see all these jQuery AJAX calls. I've seen other people's implementation, where you don't see anything in FireBug > Net > XHR.
Does anyone have any ideas how this is implemented?
Any advice would be greatly appreciated.
Cheers,
Mosh
PS: Just to emphasize, I'm not interested in doing this with Flash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
并不像看起来那么简单,
我认为这会涉及一些低级的 Web 服务器编程,因为在执行代码之前正在处理(上传)文件。这仅仅意味着您没有深入了解 Web 服务器的内部文件上传过程来轮询/调查它...
如果您的场景实际上应如下工作:
那么您将这里有几个问题:
iframe
中上传文件并从父页面进行轮询上传,则必须实现一些低级服务器代码来提供我上面突出显示的内容。客户端插件
这就是为什么在客户端使用诸如 Uploadify 之类的插件来完成此操作要容易得多使用 Flash 获取有关向服务器上传进度的信息。
Not as simple as it seems
I think this would involve some low level web server programming, because files are being processed (uploaded) before your code gets executed. This simply means that you don't have an insight into web server's internall file uploading process to poll/investigate it...
If your scenario should actually work as:
then you'd have several problems here:
iframe
and poll uploading from parent page, you'd have to implement some of the low level server code to provide what I've highlighted above.Client-side plugins
That's why it's much easier to do this on the client side using plugins like Uploadify that may as well use Flash to get information about upload progress toward the server.
简单:
http://www.uploadify.com/
simple :
http://www.uploadify.com/
也许此页面可以帮助您: 带进度条的 jquery ajax 上传器插件。或者您可以自己寻找替代方案。
Maybe this page can help you out: jquery ajax uploader plugin with progress bar. Or you can search for an alternative yourself.
这似乎实际上是几个问题合二为一的。
我可以建议的一项改进是使用 Socket.io 库,它使用 websockets,并回退到 long-通过 XHR 或 Flash 进行轮询。它至少会提供一种最小化轮询开销的结构化方法。
当谈到“隐藏请求”时,他们可能使用与 XHR 不同的方法,如果您没有看到 XHR,他们可能没有执行 XHR。 (这很明显)
That seems to actually be several questions in one.
One improvement I can suggest is to use the Socket.io library, it uses websockets, and fallbacks to long-polling via XHR, or via Flash. It would at least provide a structured way of minimizing polling overhead.
When it comes the "hidden requests" they probably use a different method than XHR, if you are not seeing the XHR's, they are probably not doing XHR's. (That's kind of obvious)