原来的代码:
function getcourse()
{
sendmsg="coursecategid="+document.getElementById("coursecate").value;
// window.alert(sendmsg);
S_xmlhttprequest();
$url=_webRoot_+"/main/getcourse/";
//$url="http://localhost/rr/main/getcourse/";
//alert($url);
xmlHttp.open("POST",$url,true);
xmlHttp.onreadystatechange=courselist;
xmlHttp.setrequestheader("content-length",sendmsg.length);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(sendmsg);
}
function getemployees()
{
senddeptmsg="deptid="+document.getElementById("deptlist").value;
S_xmlhttprequest();
$url=_webRoot_+"/main/getemployees/";
xmlHttp.open("POST",$url,true);
xmlHttp.onreadystatechange=employeeslist;
xmlHttp.setrequestheader("content-length",senddeptmsg.length);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(senddeptmsg);
}
window.οnlοad=function()
{
getemployees();
getcourse();
}
原因分析:应该是2次请求后台有冲突,所以改为顺序发送请求,以前是并行发送
修改
function getemployees()
{
senddeptmsg="deptid="+document.getElementById("deptlist").value;
S_xmlhttprequest();
$url=_webRoot_+"/main/getemployees/";
xmlHttp.open("POST",$url,false);
xmlHttp.onreadystatechange=employeeslist;
xmlHttp.setrequestheader("content-length",senddeptmsg.length);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(senddeptmsg);
}
xmlHttp.open("POST",$url,false); 这个是同步,就是第一个方法执行完,才继续走下面的程序
xmlHttp.open("POST",$url,true); true是异步,就是不等上面执行完,