Posted in Javascript onApril 21, 2014
获取XmlHttpRequest对象
//1 function getXMLHttpRequest() { var xmlHttpReq; try { // Firefox, Opera 8.0+, Safari xmlHttpReq = new XMLHttpRequest(); } catch (e) { try {// Internet Explorer xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } return xmlHttpReq; } //2 function getXMLHttpRequest() { var xmlHttpReq = null; if (window.ActiveXObject) {// Internet Explorer xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0"); } else if (window.XMLHttpRequest) { xmlHttpReq = new XMLHttpRequest(); } return xmlHttpReq; } //3 function getXMLHttpRequest() { var xmlHttpReq = null; if (window.XMLHttpRequest) {// Mozilla Firefox, Opera 8.0+, Safari xmlHttpReq = new XMLHttpRequest(); } else { if (window.ActiveXObject) {// Internet Explorer try { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try {// Internet Explorer xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { } } } } return xmlHttpReq; }
三种方式获取XMLHttpRequest对象
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@