兼容的XMLHttpRequest对象
对于IE7+和Firefox、Chrome、Safari, Opera, 直接使用 var xhr = new XMLHttpRequest();
对老版本IE, 使用 var xhr = new ActiveXObject("Microsoft.XMLHTTP");
所以, 封装一个兼容至IE5的XMLHttpRequest对象:
function getXHR(){ if(window.XMLHttpRequest){ var xhr = new XMLHttpRequest(); }else if(window.ActiveXObject){ var xhr = new ActiveXObject("Microsoft.XMLHTTP"); }else{ return false; } return xhr; }