Is there a function to find the amount bytes currently loaded from a file with XMLHtttpRequest?
I'm trying to write a loading screen using the file size and the amount of bytes loaded from the file. I'm able to get the file size with the XmlHttpRequest.getResponseHeader ("Content-Length")
but I want to get the size of the file loaded so far in order for me to write a function that will update a 开发者_Go百科<div>
on my my webpage to show the percentage loaded so far.
Is there a function similar to .getResponseHeader("Content-Length")
that will return the current amount of the file loaded instead of the total file size?
Cheers,
DezXMLHttRequest.responseText.length will probably be correct.
You will need to make sure you get the value when onreadystatechange == 3
to get the amount of bytes loaded so far. you can then use that data to calculate your loading screen. If you use it when onreadystatechange == 4
it will give you the amount of bytes of the whole file and not the bytes sent so far.
精彩评论