码迷,mamicode.com
首页 > Web开发 > 详细

js Ajax

时间:2014-11-11 22:30:23      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   div   

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

标签:style   blog   http   io   color   ar   os   sp   div   

原文地址:http://www.cnblogs.com/dingblog/p/4090520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!