在網頁制作過程中怎樣在不刷新頁面的情況下使前臺頁面和
后臺CGI頁面保持交互一直是個問題。這里介紹兩個我在實踐中使
用的方法。
方法一:通過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
---------------------------------------------------------------
<?
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>
新聞熱點
疑難解答