备忘录

导航

多浏览器兼容的ajax操作

 

var xmlDoc,x;

function xmlhttp_async(url,onready){

if ( url==null || url=="" ) return false;
if ( window.XMLHttpRequest ){
   x 
= new window.XMLHttpRequest();
   
if(x.overrideMimeType)//ie出错
      x.overrideMimeType('text/xml');// 不定义的话aspx等 safafi/chrome有可能null值
      //https://developer.mozilla.org/cn/AJAX/%e5%bc%80%e5%a7%8b 该页内容不错
}
else if(window.ActiveXObject){
   x 
= new ActiveXObject( "Microsoft.XMLHTTP" );
}
x.open(
"GET",url,true);
x.send(
null);
if(onready!=""){
   x.onreadystatechange 
=function() {
    
if ( x.readyState==4 && (x.status==200 || x.status==304)){
     xmlDoc 
=x.responseXML;//在外面得到也行
     eval(onready);
    }
   }
}
}

 

调用使用xmlhttp_async(xml地址,读取后执行函数)

读取使用xmlDoc.getElementsByTagName("xxxx")[i].firstChild.data     其它的在firefox下空值

 

posted on 2009-04-25 08:55  bxbacn  阅读(447)  评论(0编辑  收藏  举报