引入本地angularjs 后 $http(...).success is not a function
angular.js:15697 TypeError: $http(...).success is not a function at Object.<anonymous> (books:136) at Object.invoke (angular.js:5208) at S.instance (angular.js:11814) at p (angular.js:10627) at g (angular.js:9942) at angular.js:9807 at angular.js:1968 at m.$eval (angular.js:19523) at m.$apply (angular.js:19622) at angular.js:1966
代码:
//初始化载入数据 $http({ url : 'findAll', mehtod : 'POST' }).success(function(rows){ for(var i in rows){ var row = rows[i]; $scope.rows.push(row); } });
原因,新版本的AngularJs中取消了success和error,用promise规则。
修改后代码:
//初始化载入数据 $http({ url : 'findAll', mehtod : 'POST' }).then(function (result) { //正确请求成功时处理 console.info("--初始化载入数据----正确请求成功时处理---------"+JSON.stringify(result)); for(var i in result.data){ var row = result.data[i]; $scope.rows.push(row); } }).catch(function (result) { //捕捉错误处理 console.info(JSON.stringify(result)); // alert(result.data.Message); });