zoukankan      html  css  js  c++  java
  • 使用post()方法以POST方式从服务器发送数据

    使用post()方法以POST方式从服务器发送数据

    get()方法相比,post()方法多用于以POST方式向服务器发送数据,服务器接收到数据之后,进行处理,并将处理结果返回页面,调用格式如下:

    $.post(url,[data],[callback])

    参数url为服务器请求地址,可选项data为向服务器请求时发送的数据,可选项callback参数为请求成功后执行的回调函数。

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3     <head>
     4         <title>使用post()方法以POST方式从服务器发送和获取数据</title>
     5         <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
     6         <style>
     7             #divtest
     8             {
     9                  282px;
    10             }
    11             #divtest .title
    12             {
    13                 padding: 8px;
    14                 background-color:Blue;
    15                 color:#fff;
    16                 height: 23px;
    17                 line-height: 23px;
    18                 font-size: 15px;
    19                 font-weight: bold;
    20             }
    21             ul
    22             {
    23                 float: left;
    24                  280px;
    25                 padding: 5px 0px;
    26                 margin: 0px;
    27                 font-size: 14px;
    28                 list-style-type: none;
    29             }
    30             ul li
    31             {
    32                 float: left;
    33                  280px;
    34                 height: 23px;
    35                 line-height: 23px;
    36                 padding: 3px 8px;
    37             }
    38             .fl
    39             {
    40                 float: left;
    41             }
    42             .fr
    43             {
    44                 float: right;
    45             }
    46         </style>
    47     </head>
    48     
    49     <body>
    50         <div id="divtest">
    51             <div class="title">
    52                 <span class="fl">检测数字奇偶性</span> 
    53                 <span class="fr"><input id="btnCheck" type="button" value="检测" /></span>
    54             </div>
    55             <ul>
    56                <li>请求输入一个数字 <input id="txtNumber" type="text" size="12" /></li>
    57             </ul>
    58         </div>
    59         
    60         <script type="text/javascript">
    61             $(function () {
    62                 $("#btnCheck").bind("click", function () {
    63                     $.post("./8-5.php",{
    64                         num:$("#txtNumber").val()},function (data) {
    65                         $("ul").append("<li>你输入的<b>  "
    66                         + $("#txtNumber").val() + " </b>是<b> "
    67                         + data + " </b></li>");
    68                     });
    69                 })
    70             });
    71         </script>
    72     </body>
    73 </html>
    View Code
    1 <?php
    2 $num = $_POST['num'];
    3 if($num%2==0){
    4     echo "偶数";
    5 }else{
    6     echo "奇数";
    7 }
    View Code
  • 相关阅读:
    继续尝试,在Community Server添加一个页面二
    终于可以Blog了
    额的娘咧!从哪里下手啊!
    你可能肯定没有尝试中西合壁
    oracle11g常用bug故障排查步骤
    oracle11g dataguard完全手册2switchover
    oracle11g dataguard 完全手册
    oracle外部表 初探
    使用Deinstall专用工具删除Oracle Database
    oracle11g dataguard完全手册3failover &active dataguard(完)
  • 原文地址:https://www.cnblogs.com/xuesen1995/p/4298106.html
Copyright © 2011-2022 走看看