I am uploading a file through ajax/jquery. The demo can be found here. This function will output the percentage complete:
//progress bar function
function OnProgress(event, position, total, percentComplete)
{
//Progress bar
$('#progressbox').show();
$('#progressbar').width(percentComplete + '%') //update progressbar percent complete
$('#statustxt').html(percentComplete + '%'); //update status text
if(percentComplete>50)
{
$('#statustxt').css('color','#000'); //change status text to white after 50%
}
}
But how do I get the transfer speed?
When I printed all the variables of OnProgress, I had this:
event: [OBJECT XMLHTTPREQUESTPROGRESSEVENT]
position: 25668
total: 2122576
percentComplete: 2
I have tried to output event.speed but I got undefined.
I do not want calculate the transfer speed on the server-side, and use another ajax request polling simultaneously that returns the amount downloaded, it would not be efficient.
event.target.st=event.target.st||Date.now(); duration=Date.now()-event.target.st;