httpServletRequest的异步调用,多个.do请求
当一个页面的按钮超链接到另外一个页面时,而这个页面的数据,是通过不同的多个.do请求来填充数据时,要用到异步调用。且用到
var tmpInterval=window.setInterval("getEveryPageInfo()",1000);//定时处理。
?
function getEveryPageInfo(){
?if (最后){
??window.clearInterval(tmpInterval);
??页面处理最后的处理
??return ;
?}
?var request=Request
??sendRequest(request,Url);//异步请求过程。(本人对回调进行了封装)
?}
?}。
?
?
function sendRequest(request,url){
?request.reSend(url,"",callBackInfo);
}
var Request = new function(){
?this.pool = new Array();
?this.getXMLHttp = function (){
??? for (var i = 0; i < this.pool.length; i++){
?? ? if (this.pool[i]["obj"].readyState == 0 || this.pool[i]["obj"].readyState == 4){
??? ?? return this.pool[i]["obj"];
?? ? }
??? }
?? this.pool[this.pool.length] = new Array();
?? this.pool[this.pool.length - 1]["obj"] = this.createXMLHttp();
?? return this.pool[this.pool.length - 1]["obj"];
?}
?this.createXMLHttp = function (){
???if(window.XMLHttpRequest){
? ???var xmlObj = new XMLHttpRequest();
???}
???else{
? ???var MSXML = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
? ???for(var n = 0; n < MSXML.length; n++){
?? ????try{
??? ????var xmlObj = new ActiveXObject(MSXML[n]);???????
??? ????break;
?? ????}catch(e){
?? ????}
? ???}
??? }
?
???return xmlObj;
? }
?this.reSend = function (url,data,callback){
? ? var objXMLHttp = this.getXMLHttp()
?? if(typeof(objXMLHttp) != "object"){
???? ?return ;
? ? }
? ? url += (url.indexOf("?") >= 0) ? "&random=" + new Date().getTime() : "?random=" + new Date().getTime();
?? if(data == ""){
?? ??objXMLHttp.open('GET' , url, true);
?? ??objXMLHttp.send('');
? ? }
? ? else{
??? ?objXMLHttp.open('POST' , url, true);
??? ?objXMLHttp.setRequestHeader("Content-Length",data.length);
??? ?objXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
??? ?objXMLHttp.send(data);
??? }
?? if(typeof(callback) == "function" ){
???? objXMLHttp.onreadystatechange = function (){
?????? if (objXMLHttp.readyState == 4){
????????? if(objXMLHttp.status == 200 || objXMLHttp.status == 304){
?????????? ??callback(objXMLHttp);
????????? }
????????? else{
?????????? ??//alert("Error loading page\n"+ objXMLHttp.status +":"+ objXMLHttp.statusText);
????????? }
????????? objXMLHttp.abort();
?????? }
???? }
?? }
?}
}
function callBackInfo(xmlHTTP){
??var reqXml=xmlHTTP.responseText;
? 业务处理。。。
}
执行的过程是:
一般是得到数据,在进行处理。
?