日期:2014-05-16  浏览次数:20603 次

Ajax提示新消息的问题 - Web 开发 / Ajax
会员有新消息的话,给出提示。现在问题是我在Firefox下运行良好,在IE下不能显示。
贴出代码:
JS:
JScript code
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);
}

}
}




JSP:
HTML code
<span id="result" style="color:red; visibility:hidden"></span>


------解决方案--------------------
ie6,ie8测试没问题啊
------解决方案--------------------
有可能是IE下的缓存,try
XML code
xmlhttp.open("GET", "checkNewMessage?_dc="+new Date().getTime(), true);