_index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>异步传输(隐藏帧实现)</title>
<script language="javascript">
function searchResult()
{
var searchResultStr = document.frames["hiddenFrame"].getElementById("searchResult").innerHTML;
document.frames["displayFrame"].displayInfo(searchResultStr);
}
</script>
</head>
<frameset rows="80%,20%" frameborder="1">
<frame name="displayFrame" src="display.html" noresize="noresize" />
<frame name="hiddenFrame" src="about:blank" noresize="noresize" />
<noframes>
<body topmargin="0" leftmargin="0">
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
display.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>displayFrame</title>
<script language="javascript">
function saveResult(sMessage)
{
var resultDiv = document.getElementById("divStatus");
resultDiv.innerHTML = sMessage;
}
</script>
</head>
<body>
Please Input Your KyeWord!
<form action="getData.php" method="post" name="form1" target="hiddenFrame" id="form1">
<input name="key" type="text" id="key" />
<input type="submit" name="Submit" value="Search" />
</form>
<div id="divStatus"></div>
</body>
</html>
getData.php
<?
/**
* json application
* @author: loosboo
* @email: loosboo@163.com
* @date: 2007.12.25
* @reference:ajax高级程序设计
*/
header("Content-Type: text/html; charset=gb2312");
/**
* @discription: 定义全局变量
*/
$conn = null;
$result = null;
$resultArr = null;
$inArr = array();
if(count($HTTP_POST_VARS) > 0)
{
$i = 0;
foreach($HTTP_POST_VARS as $key => $value)
{
$inArr[$key] = $value;
}
}
elseif(count($HTTP_GET_VARS) > 0)
{
foreach($HTTP_GET_VARS as $key => $value)
{
$inArr[$key] = $value;
}
}
//var_dump($inArr);
$iKey=$inArr['key'];
if(empty($iKey))exit("null key!");
$sql = "select * from pagination_db where title like /"%".$iKey."%/"";
//echo $sql."<br>";
$conn = @mysql_connect("localhost","root","123") or die("Errors: ".mysql_error());
mysql_query("set names 'gb2312'");
@mysql_select_db("test",$conn) or die("Errors: ".mysql_error());
$result = @mysql_query($sql) or die("Errors: ".mysql_error());
if($result)
{
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$resultArr[] = $row;
}
}
//var_dump($resultArr);
if(!empty($resultArr))
{
foreach($resultArr as $row)
{
$trStr.= "<tr>";
$trStr.= "<td bgcolor='#FFFFFF'> ".$row['id']."</td>";
$trStr.= "<td bgcolor='#FFFFFF'> ".$row['title']."</td>";
$trStr.= "</tr>";
}
}
$reStr ="<table width='80%' border='0' cellspacing='1' bgcolor='#CCCCCC'>";
$reStr.="<tr>";
$reStr.="<td bgcolor='#FFFFFF'>编号</td>";
$reStr.="<td bgcolor='#FFFFFF'>标题</td>";
$reStr.="</tr>";
$reStr.=$trStr;
$reStr.="</table>";
?>
<script language="javascript">
window.onload = function()
{
top.frames["displayFrame"].displayResult("<?=$reStr?>");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>异步传输(隐藏帧实现)</title>
<script language="javascript">
function searchResult()
{
var searchResultStr = document.frames["hiddenFrame"].getElementById("searchResult").innerHTML;
document.frames["displayFrame"].displayInfo(searchResultStr);
}
</script>
</head>
<frameset rows="80%,20%" frameborder="1">
<frame name="displayFrame" src="display.html" noresize="noresize" />
<frame name="hiddenFrame" src="about:blank" noresize="noresize" />
<noframes>
<body topmargin="0" leftmargin="0">
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
display.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>displayFrame</title>
<script language="javascript">
function saveResult(sMessage)
{
var resultDiv = document.getElementById("divStatus");
resultDiv.innerHTML = sMessage;
}
</script>
</head>
<body>
Please Input Your KyeWord!
<form action="getData.php" method="post" name="form1" target="hiddenFrame" id="form1">
<input name="key" type="text" id="key" />
<input type="submit" name="Submit" value="Search" />
</form>
<div id="divStatus"></div>
</body>
</html>
getData.php
<?
/**
* json application
* @author: loosboo
* @email: loosboo@163.com
* @date: 2007.12.25
* @reference:ajax高级程序设计
*/
header("Content-Type: text/html; charset=gb2312");
/**
* @discription: 定义全局变量
*/
$conn = null;
$result = null;
$resultArr = null;
$inArr = array();
if(count($HTTP_POST_VARS) > 0)
{
$i = 0;
foreach($HTTP_POST_VARS as $key => $value)
{
$inArr[$key] = $value;
}
}
elseif(count($HTTP_GET_VARS) > 0)
{
foreach($HTTP_GET_VARS as $key => $value)
{
$inArr[$key] = $value;
}
}
//var_dump($inArr);
$iKey=$inArr['key'];
if(empty($iKey))exit("null key!");
$sql = "select * from pagination_db where title like /"%".$iKey."%/"";
//echo $sql."<br>";
$conn = @mysql_connect("localhost","root","123") or die("Errors: ".mysql_error());
mysql_query("set names 'gb2312'");
@mysql_select_db("test",$conn) or die("Errors: ".mysql_error());
$result = @mysql_query($sql) or die("Errors: ".mysql_error());
if($result)
{
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$resultArr[] = $row;
}
}
//var_dump($resultArr);
if(!empty($resultArr))
{
foreach($resultArr as $row)
{
$trStr.= "<tr>";
$trStr.= "<td bgcolor='#FFFFFF'> ".$row['id']."</td>";
$trStr.= "<td bgcolor='#FFFFFF'> ".$row['title']."</td>";
$trStr.= "</tr>";
}
}
$reStr ="<table width='80%' border='0' cellspacing='1' bgcolor='#CCCCCC'>";
$reStr.="<tr>";
$reStr.="<td bgcolor='#FFFFFF'>编号</td>";
$reStr.="<td bgcolor='#FFFFFF'>标题</td>";
$reStr.="</tr>";
$reStr.=$trStr;
$reStr.="</table>";
?>
<script language="javascript">
window.onload = function()
{
top.frames["displayFrame"].displayResult("<?=$reStr?>");
}
</script>