三種方式獲取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的一點(diǎn)心得
- 如何用ajax來創(chuàng)建一個XMLHttpRequest對象
- AJAX(XMLHttpRequest.status)狀態(tài)碼
- 關(guān)于安卓手機(jī)微信瀏覽器中使用XMLHttpRequest 2上傳圖片顯示字節(jié)數(shù)為0的解決辦法
相關(guān)文章
詳解用原生JavaScript實(shí)現(xiàn)jQuery的某些簡單功能
本篇文章主要對用原生JavaScript實(shí)現(xiàn)jQuery的某些簡單功能進(jìn)行詳細(xì)全面的講解,具有很好的參考價(jià)值,需要的朋友一起來看下吧2016-12-12
微信小程序websocket實(shí)現(xiàn)即時聊天功能
這篇文章主要為大家詳細(xì)介紹了微信小程序websocket實(shí)現(xiàn)即時聊天功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
JavaScript使用RegExp進(jìn)行正則匹配的方法
這篇文章主要介紹了JavaScript使用RegExp進(jìn)行正則匹配的方法,實(shí)例分析了RegExp對象在進(jìn)行正則匹配時的相關(guān)使用技巧,需要的朋友可以參考下2015-07-07
微信小程序使用radio顯示單選項(xiàng)功能【附源碼下載】
這篇文章主要介紹了微信小程序使用radio顯示單選項(xiàng)功能,涉及針對radio組件事件響應(yīng)相關(guān)操作技巧,并附帶源碼供讀者下載參考,需要的朋友可以參考下2017-12-12

