Angular 1.6提示$http.get(...).success is not a function
2017-03-17 13:59
369 查看
1.在使用Angular 1.6版本的$http服务时会抛出异常:$http.get(...).success is not a function
或者$http(...).success is not a function
异常代码如下:
[javascript]
view plain
copy
print?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
//请求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); });
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
异常信息如下:
[javascript]
view plain
copy
print?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
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
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
究其原因,新版本的AngularJs中取消了success和error,用promise规则。
更改写法:
[javascript]
view plain
copy
print?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
$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); });
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202012/12/dd90662a3ea900b7fe5eedf44fcb8160)
异常400相应:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202012/12/ff227b140abc5f373400bbe296ae2f95)
更多:
AngularJS $http简介1
使用$watch来监视属性或对象的变化
或者$http(...).success is not a function
异常代码如下:
[javascript]
view plain
copy
print?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
//请求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); });
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
//请求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); });
异常信息如下:
[javascript]
view plain
copy
print?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
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
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
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规则。
更改写法:
[javascript]
view plain
copy
print?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
$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); });
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
$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来监视属性或对象的变化
相关文章推荐
- 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问题
- $http.get is not a function
- AngularJS 报错: $http(...).success is not a function
- angualrJS跨域请求数据,老是报错: $http.jsonp(...).success is not a function
- 解决jquery submit()提交表单提示:f[s] is not a function
- 出错处理:HTTP method GET is not supported by this URL
- J2EE中HTTP method GET/Post is not supported by this URL
- 解决jquery submit()提交表单提示:f[s] is not a function
- HTTP method GET is not supported by this URL 问题解决
- 关于"HTTP method GET is not supported by this URL"的错误
- 关于ExtJS-4.0.2a中在gridpanel中出现column.getEditor is not a function的错误解决方法
- this.getColumnModel is not a function Extjs 如何解决呢? Extjs 导出 到Excel 解决方案问题
- HTTP method GET is not supported by this URL
- 访问arcgisserver报:HTTP Status 405 - HTTP method GET is not supported by this URL
- 编译错误提示:GetWeb.cpp(99) : error C2653: 'CWebPage' : is not a class or namespace name
- HTTP method GET is not supported by this URL
- 奇怪的TypeError: Error #1006: getInstance is not a function.
- is not abstract and does not override abstract method getIncludes() in org.apache.jasper.runtime.HttpJspBase 问题