I am uploading multiple files using XMLHttpRequest at the same time. I want each file to have its own progress indicator. So, when I get array of files for upload, I initiate upload for each of them inside a for cycle like
for(var i=0; i<files.length; i++)
{
// Create transfer object
var xhr = new XMLHttpRequest();
// Attach progress event handler
xhr.addEventListener('progress', function(e) { showProgress .... });
....
}
The issue is, how to pass correct "i" value to the progress callback function. In case I use "i" like this:
xhr.addEventListener('progress', function(e) { console.log(i); });
I always get the latest "i" value. In case define it like this:
xhr.addEventListener('progress', (function(i,e) { console.log(i); })(i));
I get correct I, but I never get the event object "e", so I don't get actual progress. What is correct way of defining it?