当前位置: 移动技术网 > IT编程>开发语言>PHP > php后台程序与Javascript的两种交互方式

php后台程序与Javascript的两种交互方式

2019年05月03日  | 移动技术网IT编程  | 我要评论

alcatel官网,沃热尔,蜀山战纪第三季迅雷下载

方法一:通过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>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网