If you use FireFox (and I'm sure most browsers other than IE), then there really is a way to tell how much data was transferred during the XHR operation. If the operation in question sends the correct header, it is quite simple to use this information to calculate the percentage of downloaded data.
I wrote this code to determine the percentage of data transferred to an XHR operation several years ago, so I apologize for not reflecting the years of coding experience I have received since then. I almost certainly will not write it like this now! Nevertheless, I managed to catch him and hope that he will be useful to you.
, , IE7 Explorer, , , , IE. 8 9, , . IE, , !
, beforeSend ( jQuery , ajax-), Javascript ( , 50 , , , 200 , ). , , , responseText XHR. responseText , . , length() string, , .
, , , . , . , . , , .
<script type="text/javascript">
$.ajax ({
beforeSend : function (thisXHR)
{
if (!$.browser.msie)
{
myTrigger = setInterval (function ()
{
if (thisXHR.readyState > 2)
{
var dlBytes = thisXHR.responseText.length;
if (totalBytes == -1)
totalBytes = thisXHR.getResponseHeader ('Content-length');
(totalBytes > 0)?
$('#progress').html (Math.round ((dlBytes / totalBytes) * 100) + "%"):
$('#progress').html (Math.round (dlBytes / 1024) + "K");
}
}, 50);
}
},
complete : function ()
{
if (myTrigger)
clearInterval (myTrigger);
}
});
</script>