chu*_*ubs 9 javascript rest angularjs
所以我正在使用angularjs restful service $ resource并且我正在调用$ save函数.但是,我传递给它的错误回调没有被调用.服务器发送418错误我认为,因为它不是200会导致调用错误回调.但是,它永远不会.我找不到任何文档说明http错误代码将导致调用错误回调.
这是我的代码:
var modalScope = $scope.$new();
modalScope.showPassword = false;
modalScope.message = null;
modalScope.user = new User();
modalScope.submit = function(user) {
user.$save( {}, function(data,headers) {
// do the success case
}, function(data,headers) {
// do the error case
});
};
Run Code Online (Sandbox Code Playgroud)
modalScope.user被传递给定义的提交函数.那么为什么没有调用此错误回调的问题是什么?
我在ngResource源代码中找到了以下内容
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with status
// code outside of the <200, 400) range
});
Run Code Online (Sandbox Code Playgroud)
我对范围表示法感到困惑,但它似乎应该实际调用错误方法.也许你发现了一个bug.
小智 5
有同样的问题,这里没有任何工作.原来我有一个自定义的调试拦截器没有显式返回$ q.reject(响应).
显然,每个自定义调试拦截器都会完全覆盖默认行为.
请参阅https://github.com/angular/angular.js/issues/2609#issuecomment-44452795以获取答案.
| 归档时间: |
|
| 查看次数: |
12446 次 |
| 最近记录: |