Ajax类

来源:互联网 发布:淘宝怎么设置免密支付 编辑:程序博客网 时间:2024/05/03 07:05
Ajax = {
  xmlhttp: 
function(){
    
if (window.XMLHttpRequest)    //   Mozilla,   Safari,...
         return  new XMLHttpRequest();          
    
else if(window.ActiveXObject)      //   IE
         return   new ActiveXObject("Msxml2.XMLHTTP");
    
else
         
return   new ActiveXObject('Microsoft.XMLHTTP');
  }
,
  url:
'',
  method:
'POST',
  load:
'',
  end:
'',
  agr:
'',
  returnValue:
'',
  pars:
null,
  request:
function(){  //ajax异步数据更新
   
   
var xmlhttp= this.xmlhttp();
   
var load=this.load;
   
var end=this.end;
   
var agr=this.agr;
   xmlhttp.open(
this.method,this.url,true);
   xmlhttp.setRequestHeader(
'Content-Type','application/x-www-form-urlencoded');
   xmlhttp.onreadystatechange
=function(){
         
switch (xmlhttp.readyState)
         
{
         
case 1:
           
if (typeof(load)=='function')
             
{
             load();
             }

          
else
           eval(load);
          
break;
         
case 2:

          
break;
         
case 3:
 
          
break;
         
case 4:
              
if (typeof(end)=='function')
              
{
             end(xmlhttp);
               }

          
else
            eval(end);
            
          
break;
         }

        
        
        }
;
   xmlhttp.send(
this.pars);
   
this.end='';
  }


 
}
;
原创粉丝点击