简体   繁体   English

在没有AJAX的情况下获取文件上传状态

[英]Getting file upload status without AJAX

It seems to me if information is already being output to a user by a browser it ought to be accessible in the DOM in some manner via javascript. 在我看来,如果信息已经通过浏览器输出给用户,则应该可以通过javascript以某种方式在DOM中对其进行访问。 When you upload a file using a webkit browser (and possibly others) using the good old iframe trick the browser displays an upload percent in the status bar at the bottom of the browser window. 当您使用旧版iframe技巧通过Webkit浏览器(可能还有其他浏览器)上传文件时,浏览器会在浏览器窗口底部的状态栏中显示上传百分比。 It would be pretty amazing to be able to tap into that instead of needing to query the server for that same information. 能够利用它而不用向服务器查询相同的信息将是非常令人惊讶的。 Has anyone ever tried to do so? 有没有人尝试过这样做?

I have try something like this. 我已经尝试过类似的方法。 If using old method with iframe for uploading files you can get upload information only if you have APC enable on server side (for php). 如果对iframe使用旧方法上传文件,则只有在服务器端启用APC(对于php)时,您才能获取上传信息。 With javascript the maximum that you can know is the start and the end of the upload (by using iframe onload event). 使用javascript,您可以知道的最大值是上传的开始和结束(通过使用iframe onload事件)。 So you can use an animated gif when file upload start and remove the animated gif when it ends (that causes the onload event of the iframe). 因此,您可以在文件上传开始时使用动画gif,并在结束时删除动画gif(这会导致iframe的onload事件)。

Then after upload iframe will contain any errors message of the upload status. 然后,在上传后,iframe将包含有关上传状态的任何错误消息。 You can do some more trick by returning file info as JSON when upload finish. 您可以通过在上传完成时以JSON格式返回文件信息来做一些技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM