Ajax| News
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 seconds to automatically refresh once, 1 seconds to obtain data .
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 = "You have" +strinfo+ "new Message";
}
Alert ("System hint: there is a new message, please check in time!") "); -->
if (strinfo==1)
JavaScript Document
<script type= "Text/javascript" >window.onload=refreshh () </script>//xxx.aspx file invocation