界面提交方式-Get和Post

一.Get

Get:將表單中數(shù)據(jù)的按照variable=value的形式,添加到action所指向的URL地址的后面,并且兩者用“?”連接,而各個變量之間使用“&”連接。

優(yōu)缺點:參數(shù)都體現(xiàn)在url上,可以用于翻頁,簡單查詢,get只能接收2M以下的內(nèi)容,所以有局限性,另外由于內(nèi)容是可見的,安全性就下降了。

代碼例子:

//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.輸入相關(guān)信息,例如jack,000,點擊submit
3.url變?yōu)?code>http://127.0.0.1/hello.php?name=jack&password=000
4.界面


二.Post

Post:是將表單中的數(shù)據(jù)放在form的數(shù)據(jù)體中(或者說把內(nèi)容放在了http消息體里),按照變量和值相對應(yīng)的方式,傳遞到action所指向URL。

優(yōu)缺點: 用于頁面表單提交,上傳文件,大小沒有限制,也不會在地址欄上顯示。

代碼例子:

//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.輸入相關(guān)信息,例如jack,000,點擊submit
3.url不變http://127.0.0.1/hello.php
4.界面

三.返回JSON類型數(shù)據(jù)

代碼例子:

//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.輸入相關(guān)信息,例如jack,000,點擊submit
3.url不變http://127.0.0.1/hello.php
4.界面


JSON數(shù)據(jù)轉(zhuǎn)OC模型網(wǎng)站
http://modelend.com

XML(用的越來越少了)學(xué)習(xí)網(wǎng)站
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>";
?>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標(biāo)準(zhǔn)。 注意:講述HT...
    kismetajun閱讀 28,827評論 1 45
  • redis是一個以key-value存儲的非關(guān)系型數(shù)據(jù)庫。有五種數(shù)據(jù)類型,string、hashes、list、s...
    林ze宏閱讀 1,111評論 0 0
  • 網(wǎng)絡(luò) 理論模型,分為七層物理層數(shù)據(jù)鏈路層傳輸層會話層表示層應(yīng)用層 實際應(yīng)用,分為四層鏈路層網(wǎng)絡(luò)層傳輸層應(yīng)用層 IP...
    FlyingLittlePG閱讀 968評論 0 0
  • width: 65%;border: 1px solid #ddd;outline: 1300px solid #...
    邵勝奧閱讀 5,175評論 0 1
  • 再次被《歡樂頌2》刷屏,這個叫邱瑩瑩的姑娘,渾身都是吐槽點,一旦戀愛,智商立馬歸零,實在是讓人又氣又心疼。 很多人...
    儲楊閱讀 893評論 1 4

友情鏈接更多精彩內(nèi)容