【问题标题】:Getting too much traffic error in javascript for xmlhttprequest在 xmlhttprequest 的 javascript 中出现太多流量错误
【发布时间】:2017-09-06 11:45:21
【问题描述】:

我在 javascript 中使用 xmlhttprequest() 来查找链接的状态码。

xhttp = new XMLHttpRequest();   
xhttp.timeout = 5000;
xhttp.open("GET", url, true);
xhttp.send(null);

我在一个函数中编写此代码并在 for 循环中为近 1000 个链接调用此函数。如果我在执行此操作后执行此操作,然后如果我启动 chrome 并尝试运行 anurl,则会显示类似“来自服务器的流量过多”并要求验证。

我在 Java 中也做过同样的事情,但在 java(使用 httprequest)中我没有收到任何错误。

我面临的另一个问题是我的状态代码为“0”。这是什么意思??

执行速度也很慢。有没有什么办法可以用javascript更快的找到一个url的状态码???

【问题讨论】:

  • 你为什么要调用 1k ajax 调用?
  • 浏览器有几个并发 xmlhttp 请求的限制。因此,如果您将超时设置为仅 5 秒,则不能在循环中进行 1000 次调用,因为第 10 次调用必须等待第 1 次调用完成等等。您能解释一下为什么需要调用数千个链接吗?环形?也许有一个更好的解决方案,不需要这么多的调用。
  • 我想验证页面的所有链接@madalin ivascu

标签: javascript java jquery xmlhttprequest http-status-code-404


【解决方案1】:

此代码适用于 xmlhttprequest :

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
   // Typical action to be performed when the document is ready:
   document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "filename", true);
xhttp.send();

【讨论】:

    猜你喜欢
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 2010-09-19
    • 2016-03-18
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    相关资源
    最近更新 更多