I have a function which showing progress of uploading files to the server:
function progress(event) {
...
}
...
for (var i = 0; i<files.length; i++) {
xhr.upload.onprogress = progress;
}
progress function is in for loop, and executes once for every file.
In progress function I want to write how many percent is uploaded, I can do it for one file, but if I uploading not one file, then I don’t know how to make progress for every file.
Can I add a parameter of loop to progress function?
You can use an anonymous function to give progress function additional parameter:
But this code will not work because progress will take the last file item every time. To avoid it you must use a closure:
P. S. Sorry, my first anwser was wrong, I’ve deleted it.