function x() { var a=null; try { a=new ActiveXObject("Msxml2.XMLHTTP"); } catch(c) { try { a=new ActiveXObject("Microsoft.XMLHTTP"); } catch(b) { a=null; } } if(!a&&typeof XMLHttpRequest!="undefined") { a=new XMLHttpRequest(); } return a; }
这个实例化方法至少支持IE、Firefox、Opera和Safari,它的一大特色是用了try…catch…,而不是经常用的if…else…,这种方式是比较稳妥和有效的。