加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

PHP与Javascript的两种交互方法

发布时间:2022-03-03 08:14:31 所属栏目:编程 来源:互联网
导读:在网页制作过程中怎样在不刷新页面的情况下使前台页面和 后台CGI页面保持交互一直是个问题。这里介绍两个我在实践中使 用的方法。 方法一:通过Cookie交互。一共是三个文件,分别为: index.htm,action.php,main.htm 原理为前台页面main.htm和后台action.php
  在网页制作过程中怎样在不刷新页面的情况下使前台页面和
  后台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>

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读