服务器脚本与Javascript的两种交互方式(以php为例)
服务器脚本与Javascript的两种交互方式(以php为例)
引用:http://www.knowsky.com/1014.html
在网页制作过程中怎样在不刷新页面的情况下使前台页面和后台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
------------------------------------------------------------------------------------------------------------------------------
<?php
srand((double)microtime()*1000000);
$result=rand(0,100);
setcookie("action",$result,time()+900,"/");
?>
------------------------------------------------------------------------------------------------------------------------------
main.htm
------------------------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>Test</title>
&l
相关文档:
Javascript 正则表达式使用手册
Javascript 2008-10-30 10:15 阅读97 评论0
字号: 大大 中中 小小
一.正则表达式匹配常用语法
“+”字符:规定表达式字符出现一次或多次。
“*”字符:规定表达式字符出现零次或多次。
“? ......
javascript 设置cookie注意事项
javascript 设置cookie注意事项
在Javascript 中,cookie 可以通过 document.cookie进行设置,当设置多个cookie时浏览器会自动把
它们用分号隔开。如下:
document.cookie = 'cookie1';
document.cookie ='cookie2';
alert (document.cookie) ;//输出 cookie1 ; cookie2
但是如果把第 ......
进行文件的读和写,先打开一个文件,然后开始读或者写文件,最后再关系这个文件资源。
如,文件的读操作:
<?php
$file = fopen('your file path','r');
while(!feof($file)){ //当没有读取到文件结尾,继续循环读取操作
$line = fgets($file); //读取到一行的内容
echo $line.'<br/>';
}
fclose($file) ......
#apt-get install apache2
//安装apahce2
#apt-get install php5
//安装php5
#apt-get install mysql-server
//安装mysql服务端
#apt-get install mysql-myclient
//安装mysql的客户端
#apt-get install php-mysql
//安装php-mysql的连结
apache+php+mysql 环境已经搭建好了
将以下的服务重启一下
#/et ......
大家可能都遇到过在写javascirpt代码时传递中文,在后台取到时发现是乱码,这里把我今天做的方法写出来,希望对大家以后有用!
方法(一):
html页面:
function testOne() {
var url = "testOne_test.do?expr="+你好;
location = encodeURI(url);
}
后台java代码:
String expr = ne ......