我正在使用Angular $http.post
请求,我的回复是在大约5-8 min
之后发生的,所以Angulars在这里失败,因为当响应没有在特定时间发送而不是发回第二个请求时我们如何设置请求响应的时间来等一下?
答案 0 :(得分:1)
你可以使用$ http中的超时属性。
下面有get
的示例
app.run(function($http, $q, $timeout){
var deferred = $q.defer();
$http.get('/path/to/api', { timeout: deferred.promise })
.then(function(){
// success handler
},function(reject){
// error handler
if(reject.status === 0) {
// $http timeout
} else {
// response error status from server
}
});
$timeout(function() {
deferred.resolve(); // this aborts the request!
}, 1000);
});
在docs
中详细了解相关信息