三種方式獲取XMLHttpRequest對象
更新時間:2014年04月21日 11:44:21 作者:
這篇文章主要介紹了獲取XMLHttpRequest對象的三種方式,需要的朋友可以參考下
獲取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;
}
復(fù)制代碼 代碼如下:
//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;
}
您可能感興趣的文章:
- Javascript+XMLHttpRequest+asp.net無刷新讀取數(shù)據(jù)庫數(shù)據(jù)
- javascript XMLHttpRequest對象全面剖析
- XMLHTTPRequest的屬性和方法簡介
- js判斷IE6/IE7/FF的代碼[XMLHttpRequest]
- 分享XmlHttpRequest調(diào)用Webservice的一點心得
- 如何用ajax來創(chuàng)建一個XMLHttpRequest對象
- AJAX(XMLHttpRequest.status)狀態(tài)碼
- 關(guān)于安卓手機微信瀏覽器中使用XMLHttpRequest 2上傳圖片顯示字節(jié)數(shù)為0的解決辦法
相關(guān)文章
javascript實現(xiàn)設(shè)置、獲取和刪除Cookie的方法
這篇文章主要介紹了javascript實現(xiàn)設(shè)置、獲取和刪除Cookie的方法,涉及javascript操作cookie的常用技巧,非常簡單實用,需要的朋友可以參考下2015-06-06JS保留小數(shù)點(四舍五入、四舍六入)實現(xiàn)思路及實例
保留兩位小數(shù):將浮點數(shù)四舍五入,取小數(shù)點后2位;如:2,會在2后面補上00.即2.00,感興趣的朋友看下具體的實現(xiàn)思路及代碼2013-04-04javascript實現(xiàn)禁止復(fù)制網(wǎng)頁內(nèi)容匯總
本文給大家匯總介紹了幾種使用javascript和CSS實現(xiàn)禁止復(fù)制頁面內(nèi)容的方法,非常的實用,有需要的小伙伴可以參考下。2015-12-12微信小程序開發(fā)之選項卡(窗口底部TabBar)頁面切換
本文主要介紹了微信小程序開發(fā)之選項卡(窗口底部TabBar)頁面切換的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04用JS實現(xiàn)網(wǎng)頁元素陰影效果的研究總結(jié)
用JS實現(xiàn)網(wǎng)頁元素陰影效果的研究總結(jié)...2007-08-08