日期:2014-05-16  浏览次数:20455 次

创建ajax对象的问题
function   fun_Iframe(obj){   alert(document.getElementById(obj).document.body.innerHTML);   };

function   XHConn(f_url)
{
var   xmlhttp,   bComplete   =   false;
try   {   xmlhttp   =   new   ActiveXObject( "1Msxml2.XMLHTTP ");   }
catch   (e)   {   try   {   xmlhttp   =   new   ActiveXObject( "1Microsoft.XMLHTTP ");   }
catch   (e)   {   try   {   xmlhttp   =   new   XMLHttpRequest();   }
catch   (e)   {   xmlhttp   =   false;   }}}

this.Method   =   "GET ";
this.URL   =   f_url;
this.Data   =   " ";
this.Text   =   function(){
//if(xmlhttp) {
//return   xmlhttp.responseText;   }   else   {
//return   ifr.document.body.innerHTML;   };  
};
this.onComplete   =   function(){};
this.onError   =   function(){};
this.Abort   =   function(){   if(xmlhttp)   {   xmlhttp.abort();   };   };
this.Iframe   =   "aiframe "+Math.round(Math.random()*1000);

if   (!xmlhttp){
var   ifr   =   document.createElement( "iframe ");
document.getElementsByTagName( "head ")[0].appendChild(ifr);
ifr.id   =   this.Iframe;
ifr.attachEvent( "onload ",fun_Iframe(this.Iframe))
//ifr.onload   =   fun_Iframe.call(this,this.Iframe);
};

this.Send   =   function()
{
bComplete   =   false;
sMethod   =   this.Method.toUpperCase();
sURL=this.URL;
sVars=this.Data;
fnDone=this.onComplete;
fnError=this.onError;

if   (!xmlhttp){
try   {   ifr.src   =   sURL;   }   catch(e)   {   return   false;   }
return   true;
};

try   {
if   (sMethod   ==   "GET ")
{
xmlhttp.open(sMethod,   sURL,   true);
sVars   =   " ";
}
else
{
xmlhttp.open(sMethod,   sURL,   true);
xmlhttp.setRequestHeader( "Method ",   "POST   "+sURL+ "   HTTP/1.1 ");
xmlhttp.setRequestHeader( "Content-Type ",   "application/x-www-form-urlencoded ");
}
xmlhttp.onreadystatechange   =   function(){
if   (xmlhttp.readyState   ==   4   &&   !bComplete)
{
bComplete   =   true;
if   (xmlhttp.status   ==   200)   {   fnDone();}   else   {   fnError();   };
}};
xmlhttp.send(sVars);
}
catch(z)   {   return   false;   }
return   true;
};
return   this;
}

这个本来是一个xmlhttp对象类
是可以用的
但我想加入如果不支持xmlhttp就用iframe代替
但怎么写也不行
求高手帮忙啊

------解决方案--------------------
try { xmlhttp = new ActiveXObject( "1Msxml2.XMLHTTP "); }
catch (e) { try { xmlhttp = new ActiveXObject( "1Microsoft.XMLHTTP "); }

怎么是 “1Msxml2.XMLHTTP”明明是 Msxml2.XMLHTTP,下面的问题一样