I have an Html input file that lets upload images and is sand with ajax to asp.net MVC controller, everything is working fine.
But I'm having trouble with updating a simple progress bar.
This is the simple Html,
<input type="file" multiple="multiple" id="file_upload" />
<br />
<input type="button" id="upload" name="upload" value="Upload" class="btn btn-primary btn-block" />
<br />
<div class="outter">
<div class="inner" id="progress"></div>
</div>
<br />
In my javascript, I am splitting the request to upload 10 images at a time, here is how it looks,
<script>
var counter = 0;
$("#upload").click(function () {
var fileUpload = $("#file_upload").get(0);
var files = fileUpload.files;
var devide = devider(files.length);
for (var x = 0; x < devide; x++) {
var fileData = new FormData();
for (var i = 0; i < files.length / devide; i++) {
if (counter < files.length) {
fileData.append(files[counter].name, files[counter]);
counter++;
}
}
$.ajax({
type: "POST",
url: "/Upload/GetFiles",
data: fileData,
cache: false,
contentType: false,
processData: false,
async: false,
success: function (result) {
console.log(result);
},
error: function (xhr, status, error) { console.log('Error:' + error); },
timeout: 0
});
}
});
function devider(number) {
var count = 0;
for (var i = 0; i < number; i+=10) {
count++;
}
return count;
}
</script>
I just need to update the width of the <div id="progress">
each time a file is uploaded which would probably mean in the second for loop.
but I can't since it is in a loop it is not updating the HTML?
p.s. I am aware of setInterval but I don't know how to implement it in this situation!?