var timeout = null; setinterval function handle
var xmlHttp = false; //
Initializing the XMLHttpRequest Object
function Createxmlhttp () {
XmlHttp = false;
if (window. ActiveXObject) {
try {xmlHttp = new ActiveXObject ("Msxml2.xmlhttp");}
catch (e) {xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");}
}else if (window. XMLHttpRequest) {xmlHttp = new XMLHttpRequest ();}
}
Asynchronously calls the page to fetch the result timestamp in order not to let the browser cache the result
function SendRequest () {
Createxmlhttp ();
var url = "/message/getmessage.asp tutorial? timestamp=" + New Date (). GetTime ();
if (!xmlhttp) {
Alert ("XMLHttpRequest is not create!");
}
Xmlhttp.open ("Get", url, True);
Xmlhttp.onreadystatechange = function () {//callback function start
var tag = document.getElementById ("newmsg");
tag.innerhtml = "";
if (xmlhttp.readystate = = 4 && xmlhttp.status = 200) {
if (xmlhttp.responsetext>0) {
Tag.innerhtml= "}else{
Tag.innerhtml= "";
}
}
}//callback function ends
Xmlhttp.send (NULL);
}
//Start automatic refresh
Function Update () {
Timeout = window.setinterval ("SendRequest ()", 10000);/set 10 seconds Call Update page
}
/Stop automatic refresh
function stopupdate () {
if (timeout!= null) {
Window.clearinterval (timeout);
}
}%>