我新的AJAX处理多个Ajax请求
我面临的问题是,我有一个数据库查询需要2分钟来执行......而它在执行我希望用户得到最新的更新即每30秒发生一次从数据库处理的订单数量。
在我开始订单处理查询之前..我打印订单staus ..精细..然后我开始订单处理查询和之间如果我点击更新按钮..它等待订单处理完成然后给我更新...这里是我的代码
<html>
<head>
<script type="text/javascript">
function getupdate()
{
v=document.getElementById('test').value;
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()
{alert(v);
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("update").innerHTML=v;
//document.getElementById("chunks").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","querygoogle.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlhttp.send("process=9");
}
function chunks()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp1=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp1.onreadystatechange=function()
{
if (xmlhttp1.readyState==4 && xmlhttp.status==200)
{
document.getElementById("chunks").innerHTML=xmlhttp1.responseText;
}
}
xmlhttp1.open("POST","querygoogle1.php",true);
xmlhttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlhttp1.send("process=0");
//xmlhttp.send();
}
</script>
</head>
<body >
<span id="txtHint"></span><input name="test" type="text" id="test" onchange="getupdate();" value="3"/>
<p>Status: </p>
<div id="chunks" >
<p>Being Submitted for Analysis</p>
<p>
<input name="search" type="button" value="search" onclick="chunks();">
</p>
</div>
<p>Update: </p>
<div id="update" ></div>
</body>
</html>
任何人都可以请求帮助。谢谢
如果您的数据库查询需要2分钟,请尝试优化它们(例如,通过使用索引)。 – ThiefMaster 2010-12-04 12:01:28