开发者

Is there a function to find the amount bytes currently loaded from a file with XMLHtttpRequest?

开发者 https://www.devze.com 2023-03-22 09:56 出处:网络
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\") bu

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,

Dez


XMLHttRequest.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号