I have this code
for(var i=0; i<ObjectMover.length; i++)
{
var formdata = new FormData();
formdata.append("fl", ObjectMover[i]);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", function(ev)
{
if(ev.lengthComputable)
{
$('#pb'+i).css('width', (ev.loaded / ev.total) * 100 + "%");
}
}, false);
ajax.open("POST", "file_upload.php");
ajax.send(formdata);
}
this code is working fine but the problem is that when I upload multiple files say 3 files then it shows only the progress of 3rd upload. While it is uploading all files to the server but shows the progress of only last file. I checked by putting console.log(i); in progress event like
ajax.upload.addEventListener("progress", function(ev)
{
if(ev.lengthComputable)
{
console.log(i);
$('#pb'+i).css('width', (ev.loaded / ev.total) * 100 + "%");
}
}, false);
Console shows only last file number (3). Why? Where am I making mistake. While I have same code in other file and that works good with same as above code. With my above code, there becomes 3 progress bars for each file individually but only last (3rd) progress bar shows progress of 3rd file. I checked all my "error", "load", "progress" and "abort" events if there was error from any of them but not at all. Even all upload requests are giving message on "load" event.