界面提交方式-Get和Post

一.Get

Get:将表单中数据的按照variable=value的形式,添加到action所指向的URL地址的后面,并且两者用“?”连接,而各个变量之间使用“&”连接。

优缺点:参数都体现在url上,可以用于翻页,简单查询,get只能接收2M以下的内容,所以有局限性,另外由于内容是可见的,安全性就下降了。

代码例子:

//hello.html
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>百度一下,你就知道</title>
    </head>
    
    <body>
        <!--表单 -->
        <form action="hello.php" method="GET">
            <br>
            <!--文本框输入姓名 -->
            <center>请输入姓名:<input type="text" name="name">
            <br>
            <br>
            请输入密码:<input type="password" name="password"></center>
            <!-- 提交按钮 -->
            <br>
            <br>
            <center><input type="submit"></center>
        </form>
    </body>
</html>

//hello.php文件
<?PHP
    #获取用户输入的姓名和密码
    $name = $_GET["name"];
    $pwd = $_GET["password"];
    echo $name,$pwd;
?>

运行:
1.浏览器输入http://127.0.0.1/hello.html
2.输入相关信息,例如jack,000,点击submit
3.url变为http://127.0.0.1/hello.php?name=jack&password=000
4.界面


二.Post

Post:是将表单中的数据放在form的数据体中(或者说把内容放在了http消息体里),按照变量和值相对应的方式,传递到action所指向URL。

优缺点: 用于页面表单提交,上传文件,大小没有限制,也不会在地址栏上显示。

代码例子:

//hello.html
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>百度一下,你就知道</title>
    </head>
    
    <body>
        <!--表单 -->
        <form action="hello.php" method="POST">
            <br>
            <!--文本框输入姓名 -->
            <center>请输入姓名:<input type="text" name="name">
            <br>
            <br>
            请输入密码:<input type="password" name="password"></center>
            <!-- 提交按钮 -->
            <br>
            <br>
            <center><input type="submit"></center>
        </form>
    </body>
</html>

//hello.php
<?PHP
    #获取用户输入的姓名和密码
    $name = $_POST["name"];
    $pwd = $_POST["password"];
    echo $name,$pwd;
?>

运行:
1.浏览器输入http://127.0.0.1/hello.html
2.输入相关信息,例如jack,000,点击submit
3.url不变http://127.0.0.1/hello.php
4.界面

三.返回JSON类型数据

代码例子:

//hello.html
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>百度一下,你就知道</title>
    </head>
    
    <body>
        <!--表单 -->
        <form action="hello.php" method="POST">
            <br>
            <!--文本框输入姓名 -->
            <center>请输入姓名:<input type="text" name="name">
            <br>
            <br>
            请输入密码:<input type="password" name="password"></center>
            <!-- 提交按钮 -->
            <br>
            <br>
            <center><input type="submit"></center>
        </form>
    </body>
</html>

//hello.php
<?PHP
    #获取用户输入的姓名和密码
    $name = $_POST["name"];
    $pwd = $_POST["password"];
    
    $user = array(
             "name"=>$name,
             "password"=>$pwd,
    );

    $result = array($user,$user,$user);

    $result = array(
               "user"=>$user,
               "total"=>"2",
               "status"=>0,
    );

    header('Content-Type:application/json');
    echo json_encode($result);
?>

运行:
1.浏览器输入http://127.0.0.1/hello.html
2.输入相关信息,例如jack,000,点击submit
3.url不变http://127.0.0.1/hello.php
4.界面


JSON数据转OC模型网站
http://modelend.com

XML(用的越来越少了)学习网站
http://www.w3school.com.cn/xml/xml_intro.asp

//XML
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading> 
<body>Don't forget the meeting!</body> 
</note>
<?php
header('Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<note>",
"<to>George</to>",
"<from>John</from>", 
"<heading>Reminder</heading>", 
"<body>Don't forget the meeting!</body>", 
"</note>";
?>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 28,086评论 1 45
  • redis是一个以key-value存储的非关系型数据库。有五种数据类型,string、hashes、list、s...
    林ze宏阅读 4,610评论 0 0
  • 网络 理论模型,分为七层物理层数据链路层传输层会话层表示层应用层 实际应用,分为四层链路层网络层传输层应用层 IP...
    FlyingLittlePG阅读 4,288评论 0 0
  • width: 65%;border: 1px solid #ddd;outline: 1300px solid #...
    邵胜奥阅读 10,343评论 0 1
  • 再次被《欢乐颂2》刷屏,这个叫邱莹莹的姑娘,浑身都是吐槽点,一旦恋爱,智商立马归零,实在是让人又气又心疼。 很多人...
    储杨阅读 4,249评论 1 4