gpt4 book ai didi

javascript - onreadystatechange 仅触发一次

转载 作者:行者123 更新时间:2023-12-03 11:16:13 26 4
gpt4 key购买 nike

我的请求有以下代码:

     var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) // state of 4 is 'done'. The request has completed
{
callback(req.responseText); // The .responseText property of the request object
} else { // contains the Text returned from the request.
console.log(req.readyState);
}
};
req.open("GET", url, true);
req.send();

但是,readyState 更改为 1 并正确触发(我看到它在控制台中回显),但它根本不会进展到 2。一段时间后,它超时,我在控制台中看到以下内容:

Failed to load resource: net::ERR_CONNECTION_TIMED_OUT

Uncaught SyntaxError: Unexpected end of input

有人知道为什么会这样吗?

最佳答案

放这个

req.open("GET", url, true);
req.send();

此行上方

  req.onreadystatechange = function() {

关于javascript - onreadystatechange 仅触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27334953/

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