I'm trying to update a Bootstrap progress bar according to the percent uploaded of a file.
I'm using the following code:
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
var percentComplete = (e.loaded / e.total) * 100;
console.log(percentComplete + '% uploaded');
$('.progress-bar').css('width', percentComplete+'%')
.attr('aria-valuenow', percentComplete);
}
};
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar" id="progress-bar-file" style="width: 0.000001%"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
However it does not work. The progress bar doesn't load, although the rest of the actions do happen, including the console logging, the file loading, and arriving to the database.
Any ideas?