首页 > Web开发 > 详细

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

时间:2016-08-19 22:12:01      阅读:398      评论:0      收藏:0      [点我收藏+]

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

 

技术分享

 

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

 

 

技术分享

 

技术分享

 

<!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参数的接收

原文:http://www.cnblogs.com/leigood/p/5789038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!