js Ajax

var xhr = createXHR();  
function createXHR() {  
    try {  
        xhr = new ActiveXObject("Msxml2.XMLHTTP");//IE高版本创建XMLHTTP  
    }  
    catch(E) {  
        try {  
            xhr = new ActiveXObject("Microsoft.XMLHTTP");//IE低版本创建XMLHTTP  
        }  
        catch(E) {  
            xhr = new XMLHttpRequest();//兼容非IE浏览器,直接创建XMLHTTP对象  
        }  
    }  
    return xhr;
  
} 
xhr.open("get","test.txt",false);
//xhr.setRequestHeader("MyHeader","MyValue");
xhr.send("dingss");
if((xhr.status >=200 && xhr.status<300|| xhr.status == 304)){

    console.log(xhr.responseText);
}else{
    console.log("Request was unsuccessful: "+xhr.status);
}
//alert(typeof(xhr));
原文地址:https://www.cnblogs.com/dingblog/p/4090520.html