我使用文件进度栏上传文件。此进度条在Firefox中工作,但在我上传文件时在chrome中不工作。 在chrome fileProgress函数中,它不是在服务器上发生,而是在本地运行。
$("#upload-file").change(function () {
if (this.files && this.files[0]) {
var formData = new FormData();
formData.append('file', this.files[0]);
$.ajax({
url: serverUrl,
data: formData,
type: 'POST',
headers: { 'ApiKey': checkCookie() },
xhr: function () {
//var myXhr = $.ajaxSettings.xhr();
var myXhr = new XMLHttpRequest();
if (myXhr.upload) {
myXhr.upload.addEventListener('progress',fileProgress, false);
}
return myXhr;
},
contentType: false,
processData: false,
success: function (data) {
console.log('Success File Upload');
}
});
}
});
function fileProgress(e) {
if (e.lengthComputable) {
var max = e.total;
var current = e.loaded;
var Percentage = (current * 100) / max;
$("#upload-file-progress").css("width", Percentage + "%");
}
}