三种方式获取XMLHttpRequest对象

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

三种方式获取XMLHttpRequest对象

  2020-05-13 我要评论
获取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;
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们