天天看點

ajax 動态擷取

 var strinfo

 function getAjax()

{

 var XmlHttp;

 //Creating object of XMLHTTP in IE

 try

  {

  XmlHttp = new ActiveXObject("Msxml4.XMLHTTP");

  }

 catch(e)

  {

   try

    {

     XmlHttp = new ActiveXObject("Msxml3.XMLHTTP");

    }

   catch(e)

    {

     try

      {

       XmlHttp = new

ActiveXObject("Msxml2.XMLHTTP");

      }

     catch(e)

      {

       try

        {

         XmlHttp = new

ActiveXObject("Microsoft.XMLHTTP");

        }

       catch(oc)

        {

         XmlHttp = null;

        }

      }

    }

  }

 //Creating object of XMLHTTP in Mozilla and Safari

 if(!XmlHttp && typeof XMLHttpRequest != "undefined")

 {

  XmlHttp = new XMLHttpRequest();

  if(XmlHttp.overrideMimeType)

  {

       XmlHttp.overrideMimeType("text/xml");

      }

 }

 return XmlHttp;

}

function  refreshh()   

{   

//5秒自動重新整理一次,1秒取得一次資料.   

timer  =  window.setInterval("loadData()",5000);  

}   

<!-- 

function  loadData(){ 

 url = "message_new.aspx";

 req = getAjax();

 req.onreadystatechange = function(){

  if( req.readyState == 4 && req.status == 200 ) {

   strinfo = req.responseText;

   shownewmessage();

  }

 }

 req.open( 'GET', url, true );

 req.send( null );

}

function  shownewmessage(){  

document.all["labelnumber"].innerText ="您有 "+strinfo+" 條新消息";

}

// alert("系統提示:有新的消息,請及時檢視!"); -->

 //  if(strinfo==1)

 //JavaScript Document

//<script type="text/javascript" >window.οnlοad=refreshh();</script>//xxx.aspx檔案調用 

//獲得的message_new.aspx的内容最好用this.Response.Write("")寫出來

繼續閱讀