日期:2014-05-16 浏览次数:20603 次
window.onload = initAll;
var xmlhttp;
var time = 500;
function initAll() {
refresh();
}
function refresh() {
if (window.XMLHttpRequest) {
// 针对FireFox,Mozillar,Opera,Safari,IE7,IE8
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType("text/xml");
}
} else if (window.ActiveXObject) {
// 针对IE5,IE5.5,IE6
var activexName = [ "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ];
for ( var i = 0; i < activexName.length; i++) {
try {
xmlhttp = new ActiveXObject(activexName[i]);
break;
} catch (e) {
}
}
}
xmlhttp.onreadystatechange = callback;
xmlhttp.open("GET", "checkNewMessage", true);
xmlhttp.send(null);
}
function blink() {
var spanNode = document.getElementById("result");
spanNode.style.visibility = (spanNode.style.visibility == "hidden") ? "visible":"hidden";
setTimeout("blink()", time);
}
function callback() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var responseText = xmlhttp.responseText;
var spanNode = document.getElementById("result");
spanNode.innerHTML = responseText;
setTimeout("refresh()", 120000);
setTimeout("blink()", time);
}
}
}
<span id="result" style="color:red; visibility:hidden"></span>
xmlhttp.open("GET", "checkNewMessage?_dc="+new Date().getTime(), true);