If you want to track the progress of a form submission using XHR2's progress
event, take a look at the documentation provided on MDN. Here is a sample code snippet:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.onload = function(e) { ... };
// The HTML element for upload progress
var progressBar = document.querySelector('progress#uploadProgress');
// Listen for upload progress events
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
progressBar.value = (e.loaded / e.total) * 100;
progressBar.textContent = progressBar.value;
}
};
var form = new FormData(document.querySelector('form#uploadForm'));
xhr.send(form);
Although this code snippet tracks the progress of the entire form submission, not individual files.