【发布时间】:2011-12-15 07:38:57
【问题描述】:
我有两个 AJAX 脚本,带有 xmlhttp 请求。 但它们相互冲突,例如 AJAX 函数 2 将显示函数 1 的 xmlhttp.response。我想知道是否有办法阻止这种情况?我已经尝试添加 xmlhttp.close 但这没有用。 提前致谢!
<script>var hello = setInterval(function()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("main").innerHTML=xmlhttp.responseText;
xmlhttp.close;
}
}
xmlhttp.open("GET","ajax.php?user=" +username,true);
xmlhttp.send();
}, 1000);
</script>
<script>var anotherone = setInterval(function()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("sub").innerHTML=xmlhttp.responseText;
xmlhttp.close;
}
}
xmlhttp.open("GET","ajax.php?user=" +username +"&do=" +option,true);
xmlhttp.send();
}, 1000);
</script>
【问题讨论】:
标签: php javascript html xml ajax