Create XHR
var createXHR = function() { var xhr, last_e; var PROGIDS = [ "Msxml2.XMLHTTP.6.0", //"Msxml2.XMLHTTP.5.0", // 此版本目的是给MS Office App使用, // Web中用会弹出安全对话框 "Msxml2.XMLHTTP.4.0", // Have issues, a buggy version "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP" // The oldest version ]; var len = PROGIDS.length, i = 0; if(window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { for( ; i < len; ++i ) { try { xhr = new ActiveXObject(PROGIDS[i]); return xhr; } catch(e) { last_e = e } } } throw new Error(last_e); };
Firefox 1+, Opera 8+, Safari 1.2+, and Internet Explorer 7+ 开始支持 Native XMLHttpRequest Object.
优先使用XMLHttpRequest, 因为其更高效.