gpt4 book ai didi

javascript - AJAX 查询每次失败恰好 60 秒

转载 作者:行者123 更新时间:2023-12-02 14:53:30 25 4
gpt4 key购买 nike

我有一个 Javascript 函数,每 5 秒运行一次,并通过 jQuery AJAX 调用从同一服务器请求信息。一旦页面加载,该函数就会无限期地运行。

由于某种原因,AJAX 查询大约每两分钟就会失败一次,并显示

ERR_EMPTY_RESPONSE

在控制台中。奇怪的是,它失败了整整 60 秒,然后又开始正常工作一两分钟。

到目前为止我已经尝试过但没有成功:

  • 不同的浏览器
  • 互联网连接不同
  • 更改函数的轮询时间。 (仍然会失败 60 秒间隔。例如,每 10 秒运行一次,失败 6 次。或 5x12 或 1x60)
  • 网络搜索建议刷新我计算机上的 IP 设置

我在上一台 VPS 服务器上从未遇到过任何问题。我现在正在与 GoDaddy 共享托管上运行此程序,想知道这方面是否存在问题。不过,其他站点和对服务器的 AJAX 调用在停机期间工作正常。

我以前也通过 HTTPS 运行该网站,现在仅通过纯 HTTP 运行。不确定是否相关。

这是该函数的核心内容:

var interval = null;
function checkOrders() {
interval = window.setInterval(function () {
$.ajax({
type: "POST",
dataType: "json",
url: "http://www.chipshop.co.nz/ajax/check_orders.php",
data: {shopid : 699},
error: function(errorData) {
//handle error
},
success: function(data) {
//handle success
}
});
}, 5000); // repeat until switched off, polling every 5 seconds
}

最佳答案

已解决:事实证明问题出在 GoDaddy 托管上。太多的 POST 请求导致 60 秒内“禁止”访问该文件。更改为 GET 避免了这种情况。

This page包含用户 emrys57 的答案:

For me, the problem was caused by the hosting company (Godaddy) treating POST operations which had substantial response data (anything more than tens of kilobytes) as some sort of security threat. If more than 6 of these occurred in one minute, the host refused to execute the PHP code that responded to the POST request during the next minute. I'm not entirely sure what the host did instead, but I did see, with tcpdump, a TCP reset packet coming as the response to a POST request from the browser. This caused the http status code returned in a jqXHR object to be 0.

Changing the operations from POST to GET fixed the problem. It's not clear why Godaddy impose this limit, but changing the code was easier than changing the host.

关于javascript - AJAX 查询每次失败恰好 60 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36005072/

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