我正在尝试为我志愿参与的一个团体修复一个网站。
我正在尝试将其从 Angular 1.3.16 更新到 Angular 1.6.4,但收到一条错误消息:
TypeError: $http(...).success is not a function at b.$scope.init (angular-custom.js:107)
从我通过调试得知的情况看来,导致该问题的代码是带有 .success 和 .error 函数的 angular-custom.js 文件:
$scope.init = function(){
$http({
method: 'post',
url: url,
data: $.param({ 'type' : 'getUsers' }),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function(data, status, headers, config) {
if(data.success && !angular.isUndefined(data.data) ){
$scope.post.users = data.data;
}else{
$scope.messageFailure(data.message);
}
}).
error(function(data, status, headers, config) {
//$scope.messageFailure(data.message);
});
};
我也把文件放在了plunker The 1.3.16 files at Plunker
我知道这可能是 .success 和 .error 结果,但我不太了解 Angular 如何修复它。
我是一位自学成才的编码员,因此任何帮助都会很棒,这样我就可以启动并运行这个小组。
预先感谢您的任何建议。 杆
最佳答案
推荐您阅读这篇文章 Don't use $http's .success()
和
$http({
method: 'post',
url: url,
data: $.param({'user' : $scope.tempUser, 'type' : 'save_user' }),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
then(function(response) {
your code
excuted when post request is success
},function(response) {
your code
excuted when post request is failed
});
服务器返回响应,您可以调试以更深入地探索。
关于javascript - Angular $http(...).success 不是函数有助于重写函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688042/