I'm trying to upload file(s) and showing the upload progress at the same time by using AJAX. Below is my code:
<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 />
The result of my code only showed the upload progress, but didn't upload file(s). How can I do to make the result show the upload progress and also upload file(s) at the same time?