gpt4 book ai didi

javascript - AngularJS 资源获取失败

转载 作者:IT老高 更新时间:2023-10-28 12:50:36 25 4
gpt4 key购买 nike

有谁知道如何在 AngularJS 中检查资源是否无法获取?

例如:

//this is valid syntax
$scope.word = Word.get({ id : $routeParams.id },function() {
//this is valid, but won't be fired if the HTTP response is 404 or any other http-error code
});

//this is something along the lines of what I want to have
//(NOTE THAT THIS IS INVALID AND DOESN'T EXIST)
$scope.word = Word.get({ id : $routeParams.id },{
success : function() {
//good
},
failure : function() {
//404 or bad
}
});

有什么想法吗?

最佳答案

当出现错误时,应在您的第一个回调函数之后触发一个额外的回调函数。取自 docs和组post :

$scope.word = Word.get({ id : $routeParams.id }, function() {
//good code
}, function(response) {
//404 or bad
if(response.status === 404) {
}
});
  • HTTP GET "class" actions: Resource.action([parameters], [success], [error])
  • non-GET "class" actions: Resource.action([parameters], postData, [success], [error])
  • non-GET instance actions: instance.$action([parameters], [success], [error])

关于javascript - AngularJS 资源获取失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11598097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com