首页 > AngularJs使用Post为什么后台读不到数据

AngularJs使用Post为什么后台读不到数据

AngularJs初学者,在使用post时后台没有反应,下面是我的代码

<!doctype html>
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<title>无标题文档</title>

</head>

<body >
<div ng-controller="ajaxTest">


<button ng-click="showData(requestType,content)">huoqu</button>
<span>{{data}}</span>
<span>{{error}}</span>

</div>
<script src="ng/angular.js"></script>
<script>

angular.module("myApp",[])
       .controller("ajaxTest",function($scope,$http){
           $scope.showData = function(requestType,content){
               $http.post("http://wuzl-pc:8087/token/doService.do",
                           {
                            requestType:"com.bat.shop.token.login",
                            content:{'mobile':'1','password':'1'}
                        })
                        .success(function(data){
                   $scope.data = data;
                   alert(111);
                   }).error(function(error){
                       $scope.error = error;
                       alert(222);
                   
                       })
               }
           })

</script>
</body>
</html>


已经找到解决办法了哟,前端代码没问题,只要改一下后台就好了


回调函数中使用 $scope.$apply() 刷新一下数据


Angular默认以json格式提交数据,,一般后台默认以x-www-form-urlencode格式解析。。。所以你看看是不是这个原因?

参考:http://blog.csdn.net/u013830811/article/details/51823029

【热门文章】
【热门文章】