最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php后臺(tái)程序與Javascript的兩種交互方式

 更新時(shí)間:2009年10月25日 17:44:03   作者:  
在網(wǎng)頁(yè)制作過(guò)程中怎樣在不刷新頁(yè)面的情況下使前臺(tái)頁(yè)面和后臺(tái)CGI頁(yè)面保持交互一直是個(gè)問(wèn)題。這里介紹兩個(gè)方法。
方法一:通過(guò)Cookie交互。
一共是三個(gè)文件,分別為:index.htm,action.php,main.htm
原理為前臺(tái)頁(yè)面main.htm和后臺(tái)action.php通過(guò)頁(yè)面框架 index.htm組織起來(lái),將action.php的頁(yè)面寬度設(shè)為0,這樣并不影響顯示。action.php將信息放入cookie中,main.htm通過(guò)讀取 cookie來(lái)實(shí)現(xiàn)交互。在main.htm中也可以通過(guò)重新讀取action.php 來(lái)實(shí)現(xiàn)控制后臺(tái)CGI程序。
index.htm
復(fù)制代碼 代碼如下:

<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>本頁(yè)使用頁(yè)面框架,但是您的瀏覽器不支持。</p>
</body>
</noframes>
</html>

action.php
復(fù)制代碼 代碼如下:

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

main.htm
復(fù)制代碼 代碼如下:

<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" >
當(dāng)前參數(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>

方法二:直接通過(guò)parent.*.*來(lái)實(shí)現(xiàn)交互。
一共是三個(gè)文件,分別為:index.htm,action.php,main.htm,其中index.htm和前面的一樣。
原理為通過(guò)parent.rightFrame.test.current_cookie.value直接傳遞信息。
action.php
復(fù)制代碼 代碼如下:

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

main.htm
復(fù)制代碼 代碼如下:

<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<form name="test" >
當(dāng)前參數(shù)為<input type="text" name="current_cookie" size="80" maxlength="1000">
</form>
<br>
<a href="action.php" target="leftFrame">重新讀取Cookie</a>
</body>
</html>

相關(guān)文章

最新評(píng)論

新昌县| 舒城县| 河南省| 古浪县| 麻栗坡县| 台南县| 额济纳旗| 五家渠市| 自治县| 闽侯县| 云浮市| 固阳县| 林口县| 合山市| 丹江口市| 中宁县| 博乐市| 高陵县| 阳山县| 湘乡市| 新巴尔虎右旗| 绥芬河市| 博野县| 女性| 满洲里市| 大化| 大英县| 临颍县| 临湘市| 浦东新区| 东光县| 四子王旗| 托克逊县| 湛江市| 鄂温| 牟定县| 遂昌县| 江津市| 昌都县| 内江市| 广元市|