我正在使用angular发送http请求,如下所示.
$http({
url: url,
params: params,
method:'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
timeout: 60000 //60 seconds
}).success(function(data, status, headers, config) {
//do something
}).error(function(data, status, header, config) {
if(timedout){ //determine occurrence of timeout.
//invoke timeout handler
} else
//handle other error
}
});
Run Code Online (Sandbox Code Playgroud)
如何确定超时?
我观察到在这种情况下收到状态码"0".检查status == 0 for timeout是否安全?
请注意,我不是在询问HTTP请求超时(状态码408).
Bil*_*rza 19
我已经完成了如下...
var startTime = new Date().getTime();
$http.post(...)
.success(function(resp, status, header, config) {...})
.error(function(resp, status, header, config) {
var respTime = new Date().getTime() - startTime;
if(respTime >= config.timeout){
//time out handeling
} else{
//other error hanndling
}
});
Run Code Online (Sandbox Code Playgroud)
我刚读完了源代码.在$ httpBackend的源代码中,xhr.ontimeout没有被处理.他们应该实施xhr.ontimeout.
不幸的是,Angularjs现在不支持http超时处理.:(
| 归档时间: |
|
| 查看次数: |
8781 次 |
| 最近记录: |