在页面加载完毕时同时执行2段ajax代码 结果只能执行一段
2011-05-25 16:13
537 查看
原来的代码:
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.onload=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是异步,就是不等上面执行完,
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.onload=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是异步,就是不等上面执行完,
相关文章推荐
- jqury+ajax每秒向后台发送请求数据然后返回页面(包括jqruy页面加载完毕才执行方法)
- ajax提交数据后Action中的程序未执行完毕,页面却已经显示响应结果error
- 页面加载完毕后执行一段脚本
- 页面图片加载完毕以后执行JS代码
- 页面加载完毕后执行js函数的方法
- Ajax 同一页面同时执行多个 XMLHTTP
- jsp页面中的代码执行加载顺序介绍
- 如何确保页面中的js加载完全后再执行其他代码
- main主函数执行完毕后,是否可能会再执行一段代码
- [Ajax]便于在html页面中引用javascript显示后台数据的一段ajax代码
- 所有ajax执行完且页面加载完判断--ajaxStop
- 页面加载完成再执行js代码
- 在页面没有完全加载完毕前调用Ajax方法会出错
- 如何让ajax执行完在执行下一段代码
- 页面加载完执行的代码
- 执行ajax加载页面中的js总结
- 如何让页面刷新前执行一段js代码
- 在页面加载完后执行jQuery代码
- ajax+jQuery实现一个页面同时加载多个模块!
- 封装addLoadEvent(页面加载同时执行多个函数)