四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

php后臺程序與Javascript的兩種交互方式

方法一:通過Cookie交互。
一共是三個文件,分別為:index.htm,action.php,main.htm
原理為前臺頁面main.htm和后臺action.php通過頁面框架 index.htm組織起來,將action.php的頁面寬度設為0,這樣并不影響顯示。action.php將信息放入cookie中,main.htm通過讀取 cookie來實現交互。在main.htm中也可以通過重新讀取action.php 來實現控制后臺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
復制代碼 代碼如下:
<?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" >
當前參數為<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.*.*來實現交互。
一共是三個文件,分別為: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" >
當前參數為<input type="text" name="current_cookie" size="80" maxlength="1000">
</form>
<br>
<a href="action.php" target="leftFrame">重新讀取Cookie</a>
</body>
</html>

php技術php后臺程序與Javascript的兩種交互方式,轉載需保留來源!

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

主站蜘蛛池模板: 军营医生 (1976)| 间宫祥太朗| 小牛加速器安卓版| 鹤壁旅游必去十大景点| 张美仁爱| 电影《瞬间》| 女怕嫁错郎演员表| 爱在记忆中找你歌词| 查隆拉·诺山荣| 艾恩·格拉法德| 高雅的四字吉语| 九龙城寨电影| 法证先锋2| 四查四看自我剖析材料| 黑帮大佬和我的第365天| 曹查理林雅诗电影全集| 赵立军| 坑区| 电影英雄| 大侠霍元甲演员表| 就义诗诗配画| 伪装者 豆瓣| 美女写真116| 红灯区无删减| 贝蒂的启蒙| 地理填充图册| 叶子楣地下裁决| 误杀2剧情详细介绍| 姐妹微电影| 陈若| 天才不能承受之重| 殷雪梅| 吴朋奉| 王紫瑄| 二年级53天天练语文上册答案 | land of the lost| 附身美女| 裸色亮片| 《牵牛花》阅读答案| 妈妈写给叛逆儿子的信看哭孩子| 韩世雅演的电影有哪些|