我发送一个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,header,config) { if(timedout){ //determine occurrence of timeout. //invoke timeout handler } else //handle other error } });
如何确定超时?
我已经观察到在这种情况下接收到状态码“0”。检查状态== 0是否安全?
请注意,我不是要求HTTP请求超时(状态码408)。
我已经做了如下…
var startTime = new Date().getTime(); $http.post(...) .success(function(resp,config) {...}) .error(function(resp,config) { var respTime = new Date().getTime() - startTime; if(respTime >= config.timeout){ //time out handeling } else{ //other error hanndling } });