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.onload=refreshh();</script>//xxx.ASPx文件調用