javascript:以前写的xmlhttp池,代码

2018-09-26 20:10

阅读:452

  varPool_xmlreq=function(){
var_cacheCase=[];
_cacheCase.fetch=function(){
vari=0;
var_instance=function(){
try{
return(newActiveXObject(Msxml2.XMLHTTP.5.0));}
catch(e){
try{
return(newXMLHttpRequest());}
catch(e){
try{
return(newActiveXObject(Msxml2.XMLHTTP));}
catch(e){
try{
return(newActiveXObject(Microsoft.XMLHTTP));}
catch(e){
alert(Error:initializingxmlhttprequest!);}}}}}
for(;i<this.length;i++){
if(this[i].readyState==0this[i].readyState==4){
returnthis[i];}}
this[i]=_instance();
returnthis[i];}
this.length=function(){
return_cacheCase.length}
return_cacheCase.fetch()}
var_xmlhttpreq=_cacheCase.fetch();
with(_xmlhttpreq){
open(method,url,true);
setRequestHeader(Cache-Control,no-cache);
setRequestHeader(Content-Type,application/x-
send(data);
onreadystatechange=function(){
if(_xmlhttpreq.readyState<4)
returnfalse;
if(_xmlhttpreq.status==200_xmlhttpreq.status==304){
handler(decodeURIComponent(_xmlhttpreq.responseText));
returntrue;}
alert(Error:status_+_xmlhttpreq.status+!);
returnfalse;}}}
}
varxmlreq=newPool_xmlreq();

用法:
xmlreq.connect(post,url,postdata,function);


评论


亲,登录后才可以留言!