夺命雷公狗—angularjs—13—post参数的接收发送

我们强悍的angularjs为我们不仅仅提供了他的get接收方式,而且也有post的接收方式,我们现在做一个模拟接收后端传递过来的json的数据:

夺命雷公狗—angularjs—13—post参数的接收发送

<?php
$arr = ['user'=>'admin','pass'=>'admin888'];
$arr = json_encode($arr);
echo $arr;

夺命雷公狗—angularjs—13—post参数的接收发送

夺命雷公狗—angularjs—13—post参数的接收发送

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/amazeui.min.css">
<script src="js/jq2.js"></script>
<script src="js/amazeui.min.js"></script>
<script src="js/angular.min.js"></script>
<style>
.TextBlod { font-weight:bold; }
.Red { color:red; }
.Blue { color:blue; }
.Bgred{ background:#dd514c; color:green; }
.Bgblue{ background:#23ccfe; color:green; }
.Oncss{ background:#000000; color:#ffffff; }
</style>
</head>
<body ng-app="myapp">
<script type="text/ng-template" id="newlists">
<ul class="am-avg-sm-8" ng-repeat="c in data" ng-class-odd="Bgred" ng-class-even="Bgblue" ng-click="liClick($index)" ng-class="{true:'Oncss'}[$index == index]" >
<li>{{$index}}</li>
<li>{{c.name}}</li>
<li ng-class="{true:'Red'}[c.age > 40]">{{c.age}}</li>
<li>{{c.sex}}</li>
<li ng-class="{true:'Red',false:'Blue'}[c.dang == 1]">{{c.dang == "1"? "是":"否"}}</li>
<li>{{$first ? "是":"否"}}</li>
<li>{{$last ? "是":"否"}}</li>
<li ng-class="{true:'Red',false:'Blue'}[c.dang == 1]">{{$middle ? "是":"否"}}</li>
</ul>
<button type="button" ng-click="testCk()">主色按钮</button>
</script> <ul class="am-avg-sm-8" ng-class="TextBlod" ng-controller="news">
<li>序号</li>
<li>姓名</li>
<li>年龄</li>
<li>性别</li>
<li>党员</li>
<li>是否是首条</li>
<li>是否是尾条</li>
<li>不属于前尾</li>
</ul>
<ul class="am-avg-sm-8" ng-include src="'newlists'" ng-controller="news">
</ul>
</body>
<script>
var app = angular.module('myapp',[]);
app.controller('news',function($scope,$http){
$scope.TextBlod = 'TextBlod';
$scope.Red = 'Red';
$scope.Blue = 'Blue';
$scope.Bgred = 'Bgred';
$scope.Bgblue = 'Bgblue';
$scope.Oncss = 'Oncss';
$scope.data = ''; $http.get("data.txt").success(function(data,status,headers,config){
$scope.data = data.lists;
//console.log(status);
});
$http.get("data.txt").error(function(data,status,headers,config){}); $scope.testCk = function(){
$http.post('data.php').success(function(data,state){
console.log(data);
}); //alert('tttt');
} $scope.liClick = function(index){
$scope.index = index;
}
});
</script>
</html>

展示效果如下所示:

夺命雷公狗—angularjs—13—post参数的接收发送

发送其实也很简单:

夺命雷公狗—angularjs—13—post参数的接收发送

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/amazeui.min.css">
<script src="js/jq2.js"></script>
<script src="js/amazeui.min.js"></script>
<script src="js/angular.min.js"></script>
<style>
.TextBlod { font-weight:bold; }
.Red { color:red; }
.Blue { color:blue; }
.Bgred{ background:#dd514c; color:green; }
.Bgblue{ background:#23ccfe; color:green; }
.Oncss{ background:#000000; color:#ffffff; }
</style>
</head>
<body ng-app="myapp">
<script type="text/ng-template" id="newlists">
<ul class="am-avg-sm-8" ng-repeat="c in data" ng-class-odd="Bgred" ng-class-even="Bgblue" ng-click="liClick($index)" ng-class="{true:'Oncss'}[$index == index]" >
<li>{{$index}}</li>
<li>{{c.name}}</li>
<li ng-class="{true:'Red'}[c.age > 40]">{{c.age}}</li>
<li>{{c.sex}}</li>
<li ng-class="{true:'Red',false:'Blue'}[c.dang == 1]">{{c.dang == "1"? "是":"否"}}</li>
<li>{{$first ? "是":"否"}}</li>
<li>{{$last ? "是":"否"}}</li>
<li ng-class="{true:'Red',false:'Blue'}[c.dang == 1]">{{$middle ? "是":"否"}}</li>
</ul>
<button type="button" ng-click="testCk()">主色按钮</button>
</script> <ul class="am-avg-sm-8" ng-class="TextBlod" ng-controller="news">
<li>序号</li>
<li>姓名</li>
<li>年龄</li>
<li>性别</li>
<li>党员</li>
<li>是否是首条</li>
<li>是否是尾条</li>
<li>不属于前尾</li>
</ul>
<ul class="am-avg-sm-8" ng-include src="'newlists'" ng-controller="news">
</ul>
</body>
<script>
var app = angular.module('myapp',[]);
app.controller('news',function($scope,$http){
$scope.TextBlod = 'TextBlod';
$scope.Red = 'Red';
$scope.Blue = 'Blue';
$scope.Bgred = 'Bgred';
$scope.Bgblue = 'Bgblue';
$scope.Oncss = 'Oncss';
$scope.data = ''; $http.get("data.txt").success(function(data,status,headers,config){
$scope.data = data.lists;
//console.log(status);
});
$http.get("data.txt").error(function(data,status,headers,config){}); $scope.testCk = function(){
$http.post('data.php',[
user = 'useradmin',
pass = 'useradmin888'
]).success(function(data,state){
console.log(data);
}); //alert('tttt');
} $scope.liClick = function(index){
$scope.index = index;
}
});
</script>
</html>

然后在后端测试下:

夺命雷公狗—angularjs—13—post参数的接收发送

测试结果如下所示:

夺命雷公狗—angularjs—13—post参数的接收发送

上一篇:java中的序列化流和反序列化流


下一篇:夺命雷公狗—angularjs—23—copy拷贝对象