照着JsDOM编程艺术码了实例,关于ajax,为什么会出错

       
  html:     
   
       <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
    <title>Ajax</title>
</head>
<body>
    <div id="new"></div>
    <script type="text/javascript" src="addLoadEvent.js"></script>
    <script type="text/javascript" src="getHTTPObject.js"></script>
    <script type="text/javascript" src="getNewContent.js"></script>
</body>
</html>
   
   
   以下是js: 
    
    检查兼容性:
    function getHTTPObject(){
        if(typeof XMLHttpRequest =="undefined")
            XMLHttpRequest = function (){
                try {return new ActiveXObject("Msxml2.XMLHTTP.6.0");}
                catch (e) {} 
                try {return new ActiveXObject("Msxml2.XMLHTTP.3.0");}
                catch(e){}
                try {return new ActiveXObject("Msxml2.XMLHTTP");}
                catch(e){}
                return false;
            }
            return new XMLHttpRequest();
    }
    
    
    
    指定发送请求:
    function getNewContent(){
    var request =getHTTPObject;
    if(request){
        request.open("GET","example.txt",true);
        request.onreadystatechange = function(){
            if(request.readyState ==4){
                var para = document.createElement("p");
                var txt = document.createTextNode(request.responseText);
                para.appendChild(txt);
                document.getElementById('new').appendChild(para);
            }
        };
        request.send(null);
    }else{
        alert('Sorry.')
    }

}

addLoadEvent(getNewContent);

用浏览器打开显示错误:

getNewContent.js:4 Uncaught TypeError: request.open is not a function

为什么??
阅读 2.5k
1 个回答
var request =getHTTPObject();

粗心呵

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏