现在的位置: 首页 > 综合 > 正文

一些和ajax的资料

2013年12月04日 ⁄ 综合 ⁄ 共 2246字 ⁄ 字号 评论关闭

<p>头部可能要这样写

header("Content-Type: text/html; charset=gb2312");
header("Cache-Control: no-store, no-cache,must-revalidate");

<html>
 <head>
 <META HTTP-EQUIV="pragma" CONTENT="no-cache">
  <script>
var req;

function Initialize()
{
 try
 {
  req=new ActiveXObject("Msxml2.XMLHTTP");
 }
 catch(e)
 {
  try
  {
   req=new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch(oc)
  {
   req=null;
  }
 }

 if(!req&&typeof XMLHttpRequest!="undefined")
 {
  req=new XMLHttpRequest();
 }
 
}

function SendQuery(key)
{
 Initialize();
 //key=Math.random();
 var url="http://staff.now.nxt.cn/vhost/monitor.php?k="+key;
 
 if(req!=null)
 {
  req.onreadystatechange = Process;
  req.open("GET", url, true);
        req.send(null);
       
 }
 
}

function Process()
{
 if (req.readyState == 4)
        {
        // only if "OK"
   if (req.status == 200)
   {
    if(req.responseText=="")
     HideDiv("autocomplete");
    else
    {
     ShowDiv("autocomplete");
     document.getElementById("autocomplete").innerHTML =req.responseText;
    }
   }
   else
   {
    document.getElementById("autocomplete").innerHTML="There was a problem retrieving data:<br>"+req.statusText;
   }
  }
}

function ShowDiv(divid)
{
   if (document.layers) document.layers[divid].visibility="show";
   else document.getElementById(divid).style.visibility="visible";
}

function HideDiv(divid)
{
   if (document.layers) document.layers[divid].visibility="hide";
   else document.getElementById(divid).style.visibility="hidden";
}

function BodyLoad()
{
 //HideDiv("autocomplete");
 //document.form1.keyword.focus();
 //setTimeout("SendQuery('test')",5000);
 setInterval("SendQuery('test')",5000);
 
}
</script>
 <style type="text/css">
  <!--
  .box { border: 1px solid #000000; }
  .heading {
   font-family: Georgia, "Times New Roman", Times, serif;
   font-weight: bold;
   font-size: 24px;
  }
  .style1 {color: #0033FF}
  .style2 {color: #CC0066}
  .style3 {color: #CC0000}
  .style4 {color: #33CCCC}
  .style6 {color: #669900}
  .style7 {color: #FF0066}
  .style8 {color: #FF6600}
  -->
 </style>
 <title>服务器监控页面</title></head>
 <body onload="BodyLoad();">
  <form name="form1">
  <center>
   <input name="keyword" onKeyUp="SendQuery(this.value)" style="WIDTH:700px" autocomplete="off" style="display:none">
   <div align="left" class="box" id="autocomplete" style="WIDTH:700px;BACKGROUND-COLOR:#ccccff">读取数据中...</div>
  </center>
  </form>
     <p align="center">&nbsp;</p>
 </body>
</html>

抱歉!评论已关闭.