Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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
Javascript 如果来自后端的数据可以';50秒后无法收到回音(AngularJS)_Javascript_Angularjs - Fatal编程技术网

Javascript 如果来自后端的数据可以';50秒后无法收到回音(AngularJS)

Javascript 如果来自后端的数据可以';50秒后无法收到回音(AngularJS),javascript,angularjs,Javascript,Angularjs,嗨,伙计们 我有一些关于如何设置消息,若服务器不能在50秒内收到回来的问题。我使用angularjs工厂向服务器发送请求 $http.post("https://example.com/_ah/api/tweeting/v1/xxx?average_cycle=1&date_last_stroke=2001-01-01&do_last_bp_measaure="+do_last_bp_measaure+"&googleusername="+window.localStor

嗨,伙计们

我有一些关于如何设置消息,若服务器不能在50秒内收到回来的问题。我使用angularjs工厂向服务器发送请求

$http.post("https://example.com/_ah/api/tweeting/v1/xxx?average_cycle=1&date_last_stroke=2001-01-01&do_last_bp_measaure="+do_last_bp_measaure+"&googleusername="+window.localStorage.getItem('username_google')+"")
.success(function(r){
  alert(r)
}, function(error){
  alert(error)
})
我已尝试使用$timeout,但无法生成相同的消息:

超时–{number | Promise}–以毫秒为单位的超时,或在解析时应中止请求的承诺

例如:

    $http.post(
    "https://example.com/_ah/api/tweeting/v1/xxx?average_cycle=1&date_last_stroke=2001-01-01&do_last_bp_measaure="+do_last_bp_measaure+"&googleusername="+window.localStorage.getItem('username_google')+"",
    {
        'postData': 'whatever'
    },
    {
        'timeout': 50000 // 50 seconds
    }
    )
    .success(function (response) {
        console.log("Responsed in 50 seconds :)");
    })
    .error(function (response) {
        console.log("Timeout :("); // Of course it could be other errors
    });

检查一下,您可以通过config对其进行配置;请在对…问题的评论中提出问题。我猜如果有超时-用户应该知道错误的原因是超时或错误503-服务unavailable@KrzysztofSafjanowski好的,下次问题转到评论我想问题是如何捕捉超时事件,所以我把剩下的部分扔给了我们的提问者。对不起,我的英语不好:)