实现ajax请求

 

【HTML 代码】

 






 
{{user.username}} {{user.email}}
<script type="text/javascript" src="./js/angular.min.js" charset="utf-8"></script> <script type="text/javascript" src="ajax.js" charset="utf-8"></script>

 

 

【js代码 ajax.js】

 

 

var myModule = angular.module("HelloAjax",[]);
myModule.controller("HelloAjax",["$scope","$http",function HelloAjax($scope,$http){
    
	/*
	$scope.users=[{'username':"zhangsan","email":""},
		{'username':"zhangsan2","email":""},
		{'username':"zhangsan3","email":""}];
	*/
	$scope.get_more = function(){

		$http({
				method: "POST", 
				url: "./ajax.php",
				data:{'username':$scope.username,
					  'email':$scope.email
					}
			}).
			success(function(data, status) {
			  //$scope.status = status;
			   $scope.users = data;
			}).
			error(function(data, status) {
			  //$scope.data = data || "Request failed";
			  //$scope.status = status;
		  });
	  }


	

}]);


 

 

【PHP代码 ajax.php】

 

 $user->username,
                 'email'=>$user->email);

//返回数据库
echo json_encode($users);