国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JavaScript > 正文

PHP與Javascript的兩種交互方式

2020-03-22 16:23:36
字體:
供稿:網(wǎng)友
在網(wǎng)頁制作過程中怎樣在不刷新頁面的情況下使前臺頁面和
后臺CGI頁面保持交互一直是個問題。這里介紹兩個我在實踐中使
用的方法。

方法一:通過html' target='_blank'>Cookie交互。一共是三個文件,分別為:
index.htm,action.php,main.htm
原理為前臺頁面main.htm和后臺action.php通過頁面框架
index.htm組織起來,將action.php的頁面寬度設為0,這樣并不
影響顯示。action.php將信息放入cookie中,main.htm通過讀取
cookie來實現(xiàn)交互。在main.htm中也可以通過重新讀取action.php
來實現(xiàn)控制后臺CGI程序。

index.htm
---------------------------------------------------------------
html
head
title Test /title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
/head

frameset framespacing="0" border="false" frameborder="0" cols="0,*"
frame name="leftFrame" scrolling="no" noresize src="action.php"
frame name="rightFrame" scrolling="auto" src="main.htm"
/frameset noframes
body bgcolor="#FFFFFF"
p 本頁使用頁面框架,但是您的瀏覽器不支持。 /p
/body
/noframes
/html
---------------------------------------------------------------

action.php
---------------------------------------------------------------
?
srand((double)microtime()*1000000);
$result=rand(0,100);
setcookie("action",$result,time()+900,"/");
?
---------------------------------------------------------------

main.htm
---------------------------------------------------------------
html
head
title Test /title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
script language="javascript"
function get_cookie()
{
document.test.current_cookie.value=document.cookie;
}
/script
/head
body bgcolor="#FFFFFF"
form name="test"
當前參數(shù)為 input type="text" name="current_cookie" size="80" maxlength="1000"
/form
script language="javascript"
setInterval("get_cookie()",200);
/script
br
a href="action.php" target="leftFrame" 重新讀取Cookie /a
/body
/html
---------------------------------------------------------------

方法二:直接通過parent.*.*來實現(xiàn)交互。一共是三個文件,分別為:
index.htm,action.php,main.htm,其中index.htm和前面的一樣。
原理為通過parent.rightFrame.test.current_cookie.value直接傳遞
信息。

action.php
---------------------------------------------------------------
?
srand((double)microtime()*1000000);
$result=rand(0,100);
?
script language="javascript"
parent.rightFrame.test.current_cookie.value=" ? echo $result?
/script
---------------------------------------------------------------

main.htm
---------------------------------------------------------------
html
head
title Test /title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
/head
body bgcolor="#FFFFFF"
form name="test"
當前參數(shù)為 input type="text" name="current_cookie" size="80" maxlength="1000"
/form
br
a href="action.php" target="leftFrame" 重新讀取Cookie /a
/body
/html
本文作者:更多編程語言

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 松桃| 阿坝| 岚皋县| 安阳市| 邳州市| 禹州市| 六安市| 亚东县| 德阳市| 海城市| 凤山市| 宝山区| 乌拉特前旗| 星子县| 平乡县| 阿拉尔市| 方城县| 奉贤区| 大同市| 涡阳县| 建德市| 清苑县| 青神县| 泰宁县| 阿坝| 平舆县| 北票市| 泗阳县| 衡阳市| 五莲县| 乌拉特前旗| 冕宁县| 旌德县| 东阳市| 淳安县| 馆陶县| 绩溪县| 彭山县| 绿春县| 唐海县| 呼图壁县|