Javascript 如果我在openshift origin上多次调用同一rest Api,为什么会得到readystate undefined和状态0?
当我多次调用同一个API并一个接一个地快速调用它时,我得到readystate undefined和status 0作为响应。我的网页上有用于调用api的按钮,如果我在单击时给出间隔(例如3秒),则api工作正常。我检查了后端openAPI(swagger)rest服务,它运行良好,即使我很快调用它 因此,我尝试使用readystate进行一些测试,有趣的是,当readystate的输出为“未定义”时,readystate==4上的if条件起作用,并将输出设置为“未定义”和状态为“0”。查看最后一个else if条件 但主要的问题是,为什么在后端工作正常的情况下我没有定义?如果延迟调用,api也可以正常工作?添加延迟很难,因为最终用户可以单击屏幕上的按钮,另外我也不希望出现不必要的延迟Javascript 如果我在openshift origin上多次调用同一rest Api,为什么会得到readystate undefined和状态0?,javascript,xmlhttprequest,openshift-origin,swagger-play2,Javascript,Xmlhttprequest,Openshift Origin,Swagger Play2,当我多次调用同一个API并一个接一个地快速调用它时,我得到readystate undefined和status 0作为响应。我的网页上有用于调用api的按钮,如果我在单击时给出间隔(例如3秒),则api工作正常。我检查了后端openAPI(swagger)rest服务,它运行良好,即使我很快调用它 因此,我尝试使用readystate进行一些测试,有趣的是,当readystate的输出为“未定义”时,readystate==4上的if条件起作用,并将输出设置为“未定义”和状态为“0”。查看最后
function getDocking(url,callBackFunction,btnId){
var xmlhttp = new XMLHttpRequest();
var response;
xmlhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
//Calling the callback function displayDocking once got response from server
callBackFunction(this,btnId);
}else if(this.readyState == 4 && this.status == 400)
{
document.getElementById('warning').style.display = "block";
document.getElementById("warning").innerHTML = this.responseText;
}
else if(this.readyState == 4)
{
alert("Received for button " + btnId + " Readystate: " + this.readystate + " Status: " + this.status)
callBackFunction(this,btnId);
}
};
xmlhttp.open( "POST", url , true );
xmlhttp.send(null);
//alert("Calling docking for Button " + btnId + " with URL " + url)
}
我正在使用openshift origin,路由限制导致请求超时。我编辑了yaml文件并将其增加到60秒。默认值为30秒
haproxy.router.openshift.io/timeout: 60s
JavaScript区分大小写。在
警报(…)
行中,您需要使用this.readyState
而不是this.readyState
。可能重复@Helen您的评论对我有帮助。是的,我得到readyState=4,所以我开始搜索为什么状态为0。我使用的是openshift origin,路由上有一个请求超时限制。我增加了它,它解决了问题。谢谢