一.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>";
?>



