Board logo

标题: XMLHTTP获取服务器端信息 [打印本页]

作者: fangzhen    时间: 2008-11-12 13:20     标题: XMLHTTP获取服务器端信息

//=====================================================================
//相关函数
var XMLHttpObj=null;
function newXMLHttpRequest()
{
var xmlreq = false;
if (window.XMLHttpRequest)
{
xmlreq = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{

try
{
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e1)
{
try
{
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

}
catch (e2)
{

}

}

}
return xmlreq;
}

function ReturnFunction()
{
if(XMLHttpObj.readyState==4)
{
// 成功接收了服务器响应
if (XMLHttpObj.status==200)
{
//下面一句是重点,这里显示了返回信息的内容部分,也可以加以修改。进行其它处理

document.getElementById("detail").innerHTML = XMLHttpObj.responseText;
document.getElementById("detail").style.visibility = "visible";

//这一句是实现加载信息提示框的隐藏,也可以不要。

//document.getElementById("load").style.visibility = "hidden";

}
else
{
// 有HTTP问题发生
//document.getElementById("load").style.visibility = "hidden";
alert("HTTP error: "+XMLHttpObj.status);

}

}

}

//具体调用

var URL="getdata.php?month="+MM+"&day="+DD;
var Parm=null;
//document.getElementById("load").style.visibility = "visible";
XMLHttpObj=newXMLHttpRequest();
XMLHttpObj.onreadystatechange=ReturnFunction;
XMLHttpObj.open("POST",URL,true);
XMLHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
XMLHttpObj.send(Parm);

//数据生成

<?
require"include/conn.php";
require"include/function.php";
$month=$_GET['month'];
$day=$_GET['day'];?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css.css" rel="stylesheet" type="text/css">

<TABLE WIDTH="100%" BORDER=0 CELLPADDING="2" CELLSPACING="0">
<TR><TD><font color="red"><b>今天是农历 <? echo $month?> 月 <? echo $day?> 日</b></font></TD>
</TR>
<?
$allnum=0;
$sql="select news_id,title,month,day,content from news where passed='1' and type='27' and class_id='7' and month='$month' and day='$day'";
$result=mysql_query($sql);
if($myrow=mysql_fetch_array($result))
{
do
{
$month=$myrow['month'];
$day=$myrow['day'];
$id=$myrow['news_id'];
$content=iconv("gb2312", "UTF-8", $myrow['content']);;
$title=iconv("gb2312", "UTF-8", $myrow['title']);
if($allnum==0){
echo "<TR><TD><a href=\"news/show.php?id=$id\" target=\"_blank\"><font color=blue>? $title</font></a></TD>";
echo "<TR><TD>$content</TD>";

}else{
echo "<TR><TD><font color=blue>相关连接</font></TD>";
echo "<TR><TD><a href=\"news/show.php?id=$id\" target=\"_blank\">? $title</a></TD>";
}
$allnum++;
}while($myrow=mysql_fetch_array($result));
}else{
echo "<TR><TD>  今天没有什么节庆</TD>";
}

?>
</TABLE>
</head>
</html>

//数据显示
<td align="left" style="padding:10px" id="detail">
</td>




欢迎光临 PHP开发笔记 (http://phpvi.com/) Powered by Discuz! 6.1.0