Having recently started using ajax uploading, I wanted to include a progress bar to display the uploading process.
I implemented a registration function for progressEvent
, but unfortunately, it only ran once. This means that my progress bar was not functioning correctly.
Below is the code I used. Can you help me identify what is wrong with it and suggest the correct approach to take? Thank you!
var fileEle = document.querySelector('#file');
file.onchange = function(e){
let file = e.target.files[0];
var formData = new FormData();
formData.append('book',file);
var xhr = new XMLHttpRequest();
xhr.onprogress = function(e){
console.log(e);//this only executes once, why?
}
xhr.open('post','http://127.0.0.1:8080/profile');
xhr.send(formData);
}