更新同一页面不同div内容的问题

erldy erldy 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
var xmlHttp;
function creatXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(type,result) {
var queryString="";

//var domain = document.getElementById('domain').value;
queryString = "type=" + type;
creatXMLHttpRequest();
xmlHttp.open("GET","news.php?action=GetNews&"+queryString+"×tamp=" + new Date().getTime(),"true");
xmlHttp.onreadystatechange = handleStateChange;
//xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(null);

function handleStateChange() {
if(xmlHttp.readyState == 1) {
document.getElementById(result).style.cssText = "";
document.getElementById(result).innerHTML = "正导入数据...";
}
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById(result).style.cssText = "";
var allcon = xmlHttp.responseText;
document.getElementById(result).innerHTML = allcon;
}
}
}
}

通过上面代码更新同一页面的DIV:
<div align="left" id="nresult1"><script language="JavaScript">startRequest('XXXX','nresult1');</script></div>

<div align="left" id="nresult2"><script language="JavaScript">startRequest('ZZZZ','nresult2');</script></div>

但是出现的结果有时候是第一个DIV一直显示“正导入数据..”,第二个DIV正常,或者第一个DIV显示的跟第二个DIV一样的内容(本来应该是不一样的),到底是哪里的问题呢?多谢指教!!
...全文
评论 6
收藏 已收藏
分享
返回顶部
erldy
Ajax 52,778 成员 25,334 内容