十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這需要用ajax來實(shí)現(xiàn)

創(chuàng)新互聯(lián)公司10多年企業(yè)網(wǎng)站制作服務(wù);為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及高端網(wǎng)站定制服務(wù),企業(yè)網(wǎng)站制作及推廣,對宴會酒店設(shè)計(jì)等多個方面擁有多年的網(wǎng)站營銷經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。
index.php
html
titlephp+jquery+ajax+json簡單小例子/title
?php
header("Content-Type:text/html;charset=utf-8");
?
head
script?type="text/javascript"?src="
script?type="text/javascript"
$(function()?{
$("#subbtn").click(function()?{
var?params?=?$("input").serialize();
var?url?=?"1.php";
$.ajax({
type:?"post",
url:?url,
dataType:?"json",
data:?params,
success:?function(msg){
var?backdata?=?"您提交的姓名為:"?+?msg.name?+
"br?/?您提交的密碼為:"?+?msg.password;
$("#backdata").html(backdata);
$("#backdata").css({color:?"green"});
}
});
});
});
/script
/head
body
plabel?for="name"姓名:/label
input?id="name"?name="name"?type="text"?/
/p
plabel?for="password"密碼:/label
input?id="password"?name="password"?type="password"?/
/p
span?id="backdata"/span
pinput?id="subbtn"?type="button"?value="提交數(shù)據(jù)"?//p
/body
/html
1.php代碼:
?php
//接收數(shù)據(jù)-處理數(shù)據(jù)-返回?cái)?shù)據(jù)
echo?json_encode($_POST);
?
1:表單提交,在表單中輸入留言,然后提交表單到后臺PHP;
2:PHP接收表單數(shù)據(jù),然后處理數(shù)據(jù):一般做存表操作;
3:在另外一個頁面顯示:訪問另外一個頁面,PHP讀取表中存儲的數(shù)據(jù),顯示給用戶
通過session來儲存
?php
session_start();
$_SESSION['username'] = "userName";
?
在其它頁面直接取出就行了
?
session_start();
echo?$_SESSION['username'];
?
通過url傳向其它頁面?zhèn)鬟f參數(shù)
other.php?user=xxx
?或在php重定向到其它頁面時
$username = "xxx";
$home_url = 'logIn.php?user='.$username;
header('Location:'.$home_url);
其它頁面用$_GET["user"]來接收
3.通過表單向其它頁面?zhèn)魉蛥?shù)
其它頁面用$_POST["user"]來接收