Angular 1.6提示$http.get(...).success is not a function
来源:互联网 发布:天猫淘宝京东的区别 编辑:程序博客网 时间:2024/06/05 14:09
1.在使用Angular 1.6版本的$http服务时会抛出异常:$http.get(...).success is not a function
或者$http(...).success is not a function
异常代码如下:
- //请求api
- $http.get('/api/user/showname', {
- params: {
- name: '张三'
- }
- }).success(function (data, status, config, headers) {
- console.info(data);
- alert(data);
- }).error(function (data) {
- console.info(data);
- });
异常信息如下:
- angular.js:14328TypeError: $http.get(...).success is not a function
- at new <anonymous> (test2.html:20)
- at Object.invoke (angular.js:4842)
- at R.instance (angular.js:10695)
- at n (angular.js:9572)
- at g (angular.js:8881)
- at angular.js:8746
- at angular.js:1843
- at m.$eval (angular.js:17972)
- at m.$apply (angular.js:18072)
- at angular.js:1841
究其原因,新版本的AngularJs中取消了success和error,用promise规则。
更改写法:
- $http.get('/api/user/showname2', {
- params: {
- name: '张三',
- age: 'abc'
- }
- }).then(function (result) { //正确请求成功时处理
- console.info(result);
- alert(result.data);
- }).catch(function (result) { //捕捉错误处理
- console.info(result);
- alert(result.data.Message);
- });
异常400相应:
更多:
AngularJS $http简介1
使用$watch来监视属性或对象的变化
0 0
- Angular 1.6提示$http.get(...).success is not a function
- Angular 1.6提示$http.get(...).success is not a function
- angular 1.6 $http.get(...).success is not a function 解决办法
- 解决 $http.get(...).success is not a function问题
- AngularJS 报错: $http(...).success is not a function
- angualrJS跨域请求数据,老是报错: $http.jsonp(...).success is not a function
- Ext.get(...).getValue is not a function
- app.get is not a function解决方案
- $ is not a function
- $ is not a function
- is not a function
- angular-ui-route遇到Error: fnPtr is not a function或Error: m is not a function
- chrome浏览器提示:object is not a function
- JS中提示push is not a function
- $(...).niceScroll is not a function; $... is not a function
- Argument 'xxx' is not a function, got undefined,初学Angular的第一个坑
- angular.js文件中报错xxx is not a function 的解决方法
- Angular 出现Argument is not a function, got undefined报错
- 静态类型语言和动态类型语言
- Android中通过代码实现文件权限的修改(chmod)
- 【Linux】中有关Inode的理解
- UVA 10976 分数拆分(暴力枚举)
- [转]Android Binder设计与实现
- Angular 1.6提示$http.get(...).success is not a function
- ISBN号码
- hdu4910 找规律+大素数检测
- .net快速开发平台、快速开发平台,帮你快速开发OA、CRM、ERP等系统
- how to recover root password in Collabnet SVN Edge?
- 分布式 Git
- android startService流程梳理笔记
- 3-6月是孩子长高旺季,爸妈们要好好把握,别错过!
- VisualSVN自动同步更新到网站服务器(不同电脑)