• 33.http-post


     1 <!DOCTYPE html>
     2 <html ng-app="myApp">
     3 <head lang="en">
     4     <meta charset="UTF-8">
     5     <title>HTTP-POST</title>
     6     <script src="js/angular.js" type="text/javascript"></script>
     7 
     8 </head>
     9 <body>
    10 <div ng-controller="myCtrl">
    11     <div>{{result}}</div>
    12     <button ng-click="send()">请求</button>
    13 </div>
    14 
    15 </body>
    16 
    17 <script type="text/javascript">
    18     angular.module("myApp", [])
    19             .config(function ($httpProvider) {
    20                 $httpProvider.defaults.headers.post = {
    21                     'Content-Type': 'application/x-www-form-urlencoded'//头文件请求类型 表单方式传数据
    22                 }
    23                 $httpProvider.defaults.transformRequest =
    24                         function (obj) {
    25                             var arrStr = [];//字符对象的格式传送数据
    26                             for (var p in obj) {
    27                                 arrStr.push(encodeURIComponent(obj[p]));
    28                             }
    29                             return arrStr.join("&");
    30                         }
    31             })
    32             .controller("myCtrl", ["$scope", "$http", function ($scope, $http) {
    33                 $scope.result = "";
    34                 $scope.send = function () {
    35                     $http.post('data/post.php', {"name": "陶国荣"})
    36                             .success(function (data, status, headers, config) {
    37                                 $scope.result = data;
    38                             })
    39                 }
    40 
    41 
    42             }])
    43 
    44 
    45     /*服务端文件data/post.php
    46      <?php
    47      $str=$_POST["name"];
    48      if($str=="陶国荣"){
    49      echo "验证正确!";
    50      }else{
    51      echo "验证失败!"
    52      }
    53      ?>**/
    54 
    55 </script>
    56 
    57 </html>
    View Code 1
    <!DOCTYPE html>
    <html ng-app="myApp">
    <head lang="en">
    <meta charset="UTF-8">
    <title>HTTP-POST</title>
    <script src="js/angular.js" type="text/javascript"></script>

    </head>
    <body>
    <div ng-controller="myCtrl">
    <div>{{result}}</div>
    <button ng-click="send()">请求</button>
    </div>

    </body>

    <script type="text/javascript">
    angular.module("myApp", [])
    .config(function ($httpProvider) {
    $httpProvider.defaults.headers.post = {
    'Content-Type': 'application/x-www-form-urlencoded'//头文件请求类型 表单方式传数据
    }
    $httpProvider.defaults.transformRequest =
    function (obj) {
    var arrStr = [];//字符对象的格式传送数据
    for (var p in obj) {
    arrStr.push(encodeURIComponent(obj[p]));
    }
    return arrStr.join("&");
    }
    })
    .controller("myCtrl", ["$scope", "$http", function ($scope, $http) {
    $scope.result = "";
    $scope.send = function () {
    $http.post('data/post.php', {"name": "陶国荣"})
    .success(function (data, status, headers, config) {
    $scope.result = data;
    })
    }


    }])


    /*服务端文件data/post.php
    <?php
    $str=$_POST["name"];
    if($str=="陶国荣"){
    echo "验证正确!";
    }else{
    echo "验证失败!"
    }
    ?>**/

    </script>

    </html>
  • 相关阅读:
    CV 之基于特征的配准(3)—— 内参数标定
    Lecture18_渲染前沿话题(Advanced Topics in Rendering)_GAMES101 课堂笔记
    乱七八糟介绍一款文献检索网站,web of science
    CV 之基于特征的配准(2)—— 姿态估计
    CV 之基于特征的配准(1)—— 2D 和 3D 特征的配准
    图像分割(2)之匹配标准、匹配策略及分割评测问题
    人体姿态估计的过去、现在和未来
    Python真题练习:1041-考试座位号、1042-字符统计
    Python+OpenCV实现图像医学处理
    Python+OpenCV实现图像缺陷检测
  • 原文地址:https://www.cnblogs.com/mx2036/p/6924475.html
Copyright © 2020-2023  润新知