javascript xhr.upload 未定义。无法跟踪上传进度
我正在尝试开发一个带有进度条的 html-5 上传器。 我已完成文件的发送和接收,但进度条仍然存在。
所有示例都使用类似以下内容:
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) { ...
当我在浏览器控制台中键入此内容时,它会响应未定义
var xhr = new XMLHttpRequest(); alert(xhr.upload);
如何获取上传对象的手以便跟踪进度? 我已经在最新的 Chrome (v16) 和 Firefox (v9) 中进行了测试
I'm trying to develop a html-5 uploader with progress bar.
I've accomplished sending and receiving the file, but the progress bar remains.
All the examples uses something like:
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) { ...
When I type this in my browser console it responds with undefined
var xhr = new XMLHttpRequest(); alert(xhr.upload);
How do I get the hand of the upload object so I can track progress?
I've tested in latest Chrome (v16) and Firefox (v9)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这似乎在 chrome 控制台中有效
This seems to work in the chrome console
发现错误了。
当我在不同的浏览器环境(新选项卡)中使用控制台时,它起作用了。我发现错误是 python 的 Dajaxice 库,它显然破坏了本机 xhr 对象的一些属性。感谢您的帮助,让我思考...:-)
Note2-self:不要假设控制台在用于调试时是“干净的”。
Found the error.
When I used the console in a different browser-environment (new tab), it worked. I've located the error to be the Dajaxice library for python which apparently destroys some properties of the native xhr object. Thanks for the help, got me thinking... :-)
Note2-self: Don't assume the console is "clean" when used for debugging.
尝试直接设置
onprogress
。然后做你正在做的事情。
它应该可以工作,只需在控制台中创建一个新的 xhr,上传就在那里。您的代码中还发生了其他事情。
Try to just set the
onprogress
directly.and then do what you were doing.
It should work, just creating a new xhr in the console, upload is there. Something else is going on in your code.
这不是 dajaxice 问题本身,而是它使用的 XMLHTTMLRequest.js 库的问题,请参阅对应的已知和未修复的问题 https:/ /github.com/ilinsky/xmlhttprequest/issues/12
但在 HTML5 应用程序中使用 Dajax/DajaxIce 确实是一个阻碍
It's not dajaxice issue itself but problem of XMLHTTMLRequest.js library it uses see correspondent known and unfixed issue https://github.com/ilinsky/xmlhttprequest/issues/12
But it's really a blocker to use Dajax/DajaxIce in HTML5 applications