JS创建XMLHttpRequest对象,给出2种方法:
第一种:
var xmlHttp;
function creatHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
xmlHttp = new XMLHttpRequest();
}
}
creatHttpRequest();
第二种:
var HttpObject;
try{
HttpObject=new XMLHttpRequest();
}
catch(e){
try{
HttpObject = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
HttpObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
console.log(e.message)
alert("你的浏览器不支持AJax");
}
}
}
console.log(HttpObject);