我正在S3存储桶上传视频,希望看到进度条。 所以我编码:
reader.onload = function (e) {
var rawData = reader.result;
$.ajax({
url: S3url,
type: 'PUT',
cache: false,
processData: false,
data: rawData ,
async: false,
success: fnSuccess,
error: fnError,
crossDomain: true,
contentType: "binary/octet-stream",
xhr: function() {
console.log("xhr");
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
console.log(percentComplete);
}
}, false);
return xhr;
},
}, 'json'); //$.ajax({
}; //reader.onload = function
但是百分比没有显示在console.log中。 有什么想法吗?
答案 0 :(得分:0)
xhr
应该是$.ajaxSettings.xhr()
而不是XMLHttpRequest()
的新实例,请参阅Upload multiple image using AJAX, PHP and jQuery