服务器脚本与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
相关文档:
下面两个方法实现了数组中去掉 前面 或者 后面的 重复项
去掉前面的重复项方法 把array [1, 2, 3, 1, 4, 5]去掉前面重复项 得到 [2, 3, 1, 4, 5].
function unique(a)
{
var r = new Array();
o:for(var i = 0, n = a.length; i < n; i++) {
for(var x = i + 1 ; x < n; x++)
{
......
Javascript 正则表达式使用手册
Javascript 2008-10-30 10:15 阅读97 评论0
字号: 大大 中中 小小
一.正则表达式匹配常用语法
“+”字符:规定表达式字符出现一次或多次。
“*”字符:规定表达式字符出现零次或多次。
“? ......
进行文件的读和写,先打开一个文件,然后开始读或者写文件,最后再关系这个文件资源。
如,文件的读操作:
<?php
$file = fopen('your file path','r');
while(!feof($file)){ //当没有读取到文件结尾,继续循环读取操作
$line = fgets($file); //读取到一行的内容
echo $line.'<br/>';
}
fclose($file) ......
function urlencode( str ) {
// http://kevin.vanzonneveld.net
// + original by: Philip Peterson
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// * example 1: urlencode('Kevin van Zonneveld!');
// * returns 1: 'Kevin+van+Zonneveld%21'
&nb ......
大家可能都遇到过在写javascirpt代码时传递中文,在后台取到时发现是乱码,这里把我今天做的方法写出来,希望对大家以后有用!
方法(一):
html页面:
function testOne() {
var url = "testOne_test.do?expr="+你好;
location = encodeURI(url);
}
后台java代码:
String expr = ne ......