所以我使用
angularjs restful服务$资源,我正在调用$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
},headers) {
// do the error case
});
};
modalScope.user正被传递给定义的submit函数.那么这个错误回调没有被调用的问题是什么?
解决方法
我在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,config) {
// called asynchronously if an error occurs
// or server returns response with status
// code outside of the <200,400) range
});
我对范围符号感到困惑,但它似乎应该实际调用错误方法.也许你发现了一个错误.