Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 有没有办法知道$http请求是否超时?_Angularjs_Http - Fatal编程技术网

Angularjs 有没有办法知道$http请求是否超时?

Angularjs 有没有办法知道$http请求是否超时?,angularjs,http,Angularjs,Http,超时请求和未找到的的状态代码似乎都是404 检查请求是否由于angular中的不稳定连接(并最终重试请求)而失败的最佳方法是什么?我没有收到超时的404 刚刚运行了这个代码 $http({ method: "GET", url: "http://localhost:4789/foo", timeout: 5000}) .then( function () { console.log("all OK"); }, function (response)

超时请求和未找到的
的状态代码似乎都是404


检查请求是否由于angular中的不稳定连接(并最终重试请求)而失败的最佳方法是什么?

我没有收到超时的404

刚刚运行了这个代码

$http({ method: "GET", url: "http://localhost:4789/foo", timeout: 5000})
    .then(
    function () {
        console.log("all OK");
    },
    function (response) {
        console.log(response);
    });
针对忙碌等待的URL。5秒钟后,
$http
承诺的失败回调将触发,并响应:

Object {data: null, status: 0, headers: function, config: Object}

状态为0,而不是404。Chrome的网络选项卡将请求显示为“(已取消)”。

404是服务器端响应。“未找到资源”。客户端代码上的网络超时无法生成404。您的请求从未得到响应,无法确定请求的资源是否存在。遥不可及!=不存在,看来我搞定了这个。我显然是针对不存在的资源进行测试的,但针对的是有效的服务器。该死的大脑。我无法理解你是如何在超时和其他事情之间消除歧义的,尽管我猜状态0只是意味着“客户搞砸了”,让你去弄清楚原因。