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>

阅读 5.4k
3 个回答

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

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题