我的请求有以下代码:
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.经过一段时间它超时并且我得到了控制台:
无法加载资源:net :: ERR_CONNECTION_TIMED_OUT
未捕获的SyntaxError:意外的输入结束
任何人都知道为什么会这样?
答案 0 :(得分:1)
把这个
req.open("GET", url, true);
req.send();
在这一行之上
req.onreadystatechange = function() {
答案 1 :(得分:0)
很抱歉,这最终成为VPN问题,而不是脚本问题。
答案 2 :(得分:0)
function getLatestfileinAllPath(urls)?
{
for(i = 0;i<urls.length;i++){
run(i)
}
function run(){
var request = new XMLHttpRequest();
request.open('POST', url[i]);
request.send(JSON.stringify({"data":"some data"}));
request.onreadystatechange = function()
{
if (request.readyState === XMLHttpRequest.DONE && request.status == 200)
{
console.log(JSON.parse(request.response));
}
}
};
}
}