在 Firefox 上上传 100% 时,Html5 ajax 文件上传进度侦听器不会触发
我正在通过ajax上传文件并在上传后处理图像。 当我尝试在 Firefox 上通过 ajax 上传图像文件时,当上传百分比为 100% 但文件上传成功时,xhr 进度事件不会触发我的进度函数。
Google Chrome 在上传进度 100% 时触发,但 Firefox 不会。
Biriefly我的上传脚本:
$("#uploadbutton").click(function(){
var xhr=new XMLHttpRequest()
,fd=new FormData();
xhr.upload.addEventListener("loadstart", uploadStart, false);
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.open("POST", mainurl+"ajaxupload.php");
$.each($("#upload_input").files,function(i,file){
fd.append("files_"+i,file);
});
xhr.send(fd);
});
function uploadProgress(event){
var percentComplete = Math.round(event.loaded * 100 / event.total);
console.log("pecent ",percentComplete);
}
当上传开始时,uploadProgress函数运行1次(主要是在上传百分比80%时),但在上传完成时不触发。
I am uploading files over ajax and processing images after upload.
When I tried upload image files over ajax on firefox , xhr progress event not triggering my progress function when upload percent do 100% but file was uploading successfully .
Google chrome triggering when upload progress 100% but firefox doesn't.
Biriefly my upload script :
$("#uploadbutton").click(function(){
var xhr=new XMLHttpRequest()
,fd=new FormData();
xhr.upload.addEventListener("loadstart", uploadStart, false);
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.open("POST", mainurl+"ajaxupload.php");
$.each($("#upload_input").files,function(i,file){
fd.append("files_"+i,file);
});
xhr.send(fd);
});
function uploadProgress(event){
var percentComplete = Math.round(event.loaded * 100 / event.total);
console.log("pecent ",percentComplete);
}
When upload start , uploadProgress function runnig 1 times ( mostly when upload percent 80% ), but not triggering when upload fnish .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了当前的处理程序之外,还添加两个:load (如果成功完成则触发),loadend (总是最后触发)。
In addition to your current handlers, add two more: load (fires if successful completion), loadend (fires last, always).