我正在尝试使用AJAX上传文件并同时显示上传进度。以下是我的代码:
<script>
function pro(obj){
var file = obj.files;
$.each(file, function (i,file) {
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
$.ajax({
type: "POST",
url: "upload.php",
contentType: "application/octet-stream",
processData: false,
data : data,
xhr: function () {
var xhr = $.ajaxSettings.xhr();
xhr.upload.onprogress = function (evt) {
console.log(file.name+":"+(evt.loaded/evt.total*100)+"%");
};
return xhr;
}
});
};
reader.readAsArrayBuffer(file);
});
}
</script>
<input type="file" onchange="pro(this)" multiple />
我的代码的结果只显示了上传进度,但没有上传文件。如何使结果显示上传进度并同时上传文件?