admin管理员组文章数量:1431013
I am wondering how to get the progress of a file upload using XMLHTTPRequest. In Firefox the onprogress method does not fire at all, and in chrome it only fires after the file has finished uploading.
function fileUpload(file)
{
var formData = new FormData();
formData.append('file', file);
var xhr = new XMLHttpRequest();
xhr.onprogress = function(e)
{
alert('progress');
};
xhr.open('POST', 'post.php', true);
xhr.send(formData); // multipart/form-data
}
I am wondering how to get the progress of a file upload using XMLHTTPRequest. In Firefox the onprogress method does not fire at all, and in chrome it only fires after the file has finished uploading.
function fileUpload(file)
{
var formData = new FormData();
formData.append('file', file);
var xhr = new XMLHttpRequest();
xhr.onprogress = function(e)
{
alert('progress');
};
xhr.open('POST', 'post.php', true);
xhr.send(formData); // multipart/form-data
}
Share
Improve this question
edited Sep 14, 2011 at 0:20
Kenneth Spencer
asked Sep 14, 2011 at 0:15
Kenneth SpencerKenneth Spencer
1,55213 silver badges15 bronze badges
0
1 Answer
Reset to default 7Try xhr.upload.onprogress
. In the XMLHttpRequest2 spec XMLHttpRequest have upload attribute.
The ability to register for progress events. Both for downloads (put listeners on the XMLHttpRequest object itself) and uploads (put listeners on the XMLHttpRequestUpload object, returned by the upload attribute). http://dev.w3/2006/webapi/XMLHttpRequest-2/#differences
本文标签: javascriptHow to get progress when uploading file VIA XMLHttpRequestStack Overflow
版权声明:本文标题:javascript - How to get progress when uploading file VIA XMLHttpRequest - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745495184a2660775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论