三种方式获取XMLHttpRequest对象_Javascript教程-查字典教程网
三种方式获取XMLHttpRequest对象
三种方式获取XMLHttpRequest对象
发布时间:2016-12-30 来源:查字典编辑
摘要:获取XmlHttpRequest对象复制代码代码如下://1functiongetXMLHttpRequest(){varxmlHttpRe...

获取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;

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类