【发布时间】:2016-08-10 05:18:40
【问题描述】:
当响应时间过长时如何添加超时?我的控制器中有以下内容:
$payments.getShopStatus(data.siteUrl)
.success(function(rdata, response) {
// go to next step
})
.error(function(rdata, response) {
// tell me something's wrong
// go here if there is a three-second delay too
});
在我的工厂里,我有一个简单的 http return 来处理上面的那个:
getShopStatus: function(shop) {
var me = this;
var sUrl = String(shop);
var req = {
method: 'GET',
url: sUrl
};
return $http(req);
},
在哪里添加超时/延迟?我需要在三秒无响应延迟后强制它失败。
【问题讨论】:
-
您可以在应用配置函数中添加超时。 $httpProvider.defaults.timeout = 3000;
-
这在我的函数中的什么地方?