Angularjs
发布时间:2022-04-20 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 以角度$http确定请求超时,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我发送
一个http请求使用角度如下。
@H_
944_1@$
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,con
fig)
{
//do something
}).error(function(data,header,con
fig)
{
if(timedout)
{ //deter
mine occurrence of timeout.
//invoke timeout handler
} else
//handle other error
}
}
);
如何确定超时?
我已经观察到在这种情况下接收到状态码“0”。检查状态== 0是否安全?
请注意,我不是要求http请求超时(状态码408)。
我已经
做了如下…
@H_
944_1@var startTime = new Date().getTime(
);
$
http.post(...)
.
success(function(resp,con
fig)
{...})
.error(function(resp,con
fig)
{
var respTime = new Date().getTime() - startTime;
if(respTime >= con
fig.timeout)
{
//time out handeling
} else
{
//other error h
Anndling
}
}
);
大佬总结
以上是大佬教程为你收集整理的angularjs – 以角度$http确定请求超时全部内容,希望文章能够帮你解决angularjs – 以角度$http确定请求超时所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。