Ajax类之二

function Ajax(){
var XmlHttp = false,isComplete = false;
/*@cc_on
 @if (@_jscript_version >= 5)
 try {
 XmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
 }
 catch (e){
 try {
 XmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
 }
 catch (e2){
 XmlHttp = false
 }
 }
 @end
@*/
if (!XmlHttp && typeof XMLHttpRequest != 'undefined')
  {XmlHttp = new XMLHttpRequest()}
 this.open = function(url, method, feedback,process, arg,asyc)
 {
 if (!XmlHttp) return false;
 isComplete = false;
  var asy;
  if(asyc==null){asy=true;}
  else{asy=false;}
  if(arguments.length==2){feedback=method;method="post";}
  method = method.toUpperCase();
 try {
 if (method == "GET")
 {
 XmlHttp.open(method, url+"?"+arg,asy);
 arg = "";
 }
 else
 {
 XmlHttp.open(method, url, asy);
 try{
 // XmlHttp.setRequestHeader("Content-length", parameters.length);
 XmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    XmlHttp.setRequestHeader("Connection","close");}
    catch(e){}
 }
   XmlHttp.send(arg);
 XmlHttp.onreadystatechange = function(){
 if (XmlHttp.readyState == 4 && !isComplete)
 {
 isComplete = true;
     if(XmlHttp.status==200||XmlHttp.status==0){
       try{feedback(XmlHttp.responseText,XmlHttp);}catch(e){}}
       else{try{feedback(XmlHttp.status);}catch(e){}}
 }
     else
     {try{process(XmlHttp.readyState);}catch(e){}}
    
     };
 
 }
 catch(z) { return false; }
 return true;
 };
 return this;
};

相关文档
Posted on March 9, 2007 12:45 AM | | | Comments (0) | | TrackBacks (0)
文章评论(0)

发表评论

(如果您以前没有在这里发表过评论,您的评论需要由网站所有者的审核才会正常显示,谢谢您对我们的支持.)

相关内容