最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

PHP与&#106avascript的两种交互方式

来源:懂视网 责编:小采 时间:2020-11-27 19:02:27
文档

PHP与javascript的两种交互方式

PHP与javascript的两种交互方式:在网页制作过程中怎样在不刷新页面的情况下使前台页面和 后台CGI页面保持交互一直是个问题。这里介绍两个我在实践中使 用的方法。 方法一:通过Cookie交互。一共是三个文件,分别为: index.htm,action.php,main.htm 原理为前台页面main.htm和
推荐度:
导读PHP与javascript的两种交互方式:在网页制作过程中怎样在不刷新页面的情况下使前台页面和 后台CGI页面保持交互一直是个问题。这里介绍两个我在实践中使 用的方法。 方法一:通过Cookie交互。一共是三个文件,分别为: index.htm,action.php,main.htm 原理为前台页面main.htm和

    在网页制作过程中怎样在不刷新页面的情况下使前台页面和
后台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>
</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>
---------------------------------------------------------------  

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

PHP与javascript的两种交互方式

PHP与javascript的两种交互方式:在网页制作过程中怎样在不刷新页面的情况下使前台页面和 后台CGI页面保持交互一直是个问题。这里介绍两个我在实践中使 用的方法。 方法一:通过Cookie交互。一共是三个文件,分别为: index.htm,action.php,main.htm 原理为前台页面main.htm和
推荐度:
标签: 的方法 php 脚本
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top