首页 > 代码库 > js Ajax

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));

 

js Ajax