gpt4 book ai didi

javascript - CHRis "readyState==3"是如何工作的?

转载 作者:行者123 更新时间:2023-11-29 14:54:48 25 4
gpt4 key购买 nike

这是代码片段

xhr.onreadystatechange = function(){    if(xhr.readyState == 3){      console.log("readyState response length " + xhr.response.length);   }} 

控制台是

readyState response length: 3854 readyState response length: 33214 readyState response length: 35296 

我不知道onreadystatechange触发的时机是什么,它似乎与响应的大小有点关系,它是如何工作的?

最佳答案

What is XHR readyState=3?

拥有readyState值为 3 表示当前状态为 LOADING

So when is a readyStateChange event for that state fired?

每当异步请求确实切换到 LOADING 状态时。特别是triggered by :

Once the first byte (or more) of the response entity body has been received […] or If there is no response entity body […] Then switch to the LOADING state.

因此,当浏览器收到响应字节时,它们可以自由地使用 readyState 3 触发此事件。有些人更频繁地触发它(在每次缓冲区刷新时),其他人则不会。 The spec even says对于 readystatechange 事件:

The readyState attribute changes at some seemingly arbitrary times for historical reasons.

关于javascript - CHRis "readyState==3"是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19750274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com