简体   繁体   English

angularjs:超时无法在$ http POST请求中工作

[英]angularjs:timeout not working in $http POST request

I have the following snippet in my code which set a timeout in milliseconds for the request.But its not cancelled even if the timeout is met. 我的代码中有以下代码段,它为请求设置了以毫秒为单位的超时。但即使满足超时,它也不会被取消。

var httpURL = {
            method : URLobj.method,
            url : urlString,
            data : data,
            withCredentials : true,
            headers : URLobj.headers,
            timeout:200
    };

    this.$http(httpURL).success(successFunc).error(errorFunc);

Can someone please shed some light on how this timeout parameter can be used.I am using v1.2.26. 有人可以说明如何使用这个超时参数。我正在使用v1.2.26。

服务调用

This would be how you create a $http call with a timeout 这将是您如何使用超时创建$ http调用

$http({
        method: URLobj.method,
        url: urlstring,
        withCredentials : true,
        headers: URLobj.headers,
        timeout: 200
     }).success(function(data){
        // With the data succesfully returned, call our callback
        successFunc(data);
    }).error(function(){
        errorFunc("error");
    });
 }
});

I had config.timeout = deferred.promise; 我有config.timeout = deferred.promise; in one of my interceptor which had overridden the value that i have set. 在我的一个拦截器中,它已经覆盖了我设置的值。 Commenting it out worked for me. 评论它对我有用。

config.timeout = deferred.promise; 

下面的语法将有效

$http.post(url, parms, {timeout: 60000}).then(function(success){}, function(error){})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM