我正在为用户提供一个对话框,用于管理他们将使用FileReader
上传的照片。上传时我会显示进度条。
xhr.upload.onprogress
适用于除FireFox之外的所有浏览器。
如何让xhr.upload.onprogress
解雇?
现在使用FireFox时,xhr.upload.onprogress
甚至不会开火。
我需要对代码进行哪些更改才能在FireFox中使用,就像在IE,Chrome,Safari等中一样?
uploadFile = function () {
var xhr = new XMLHttpRequest();
//Update progress bar
xhr.upload.onprogress = function (e) {
var done = e.position || e.loaded, total = e.totalSize || e.total,
present = Math.floor(done / total * 100);
progressBar.style.width = present + "%";
lblProgressPercentage.innerHTML = present + "%";
};
//File uploaded
xhr.onload = function (x) {
//progressBarContainer.className += " uploaded";
//progressBar.innerHTML = "Uploaded!";
setTimeout(function () {
progressBar.style.width = '5%';
lblProgressPercentage.innerHTML = '0%';
}, 3000);
if (onloadCallback) { if (onloadCallback) { onloadCallback(x.target) }; };
};
xhr.open("POST", "/api/files", true);
xhr.setRequestHeader("Content-Type", "multipart/form-data", true);
xhr.setRequestHeader("X-File-Name", file.name);
xhr.setRequestHeader("X-File-Size", file.size);
xhr.setRequestHeader("X-File-Type", file.type);
xhr.setRequestHeader("X-File-IsLogo", isLogo || false);
xhr.setRequestHeader("X-File-Remove", removeFile || '');
xhr.setRequestHeader("X-File-DESTINATION", destination);
xhr.send(file);
};