请问下面的这一段代码为什么不执行啊?是不是一定要先新建一个网站,然后才能够执行啊?谢谢!
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript"> 
    var xmlhttp = false;   
    function CreateXMLHttp(){
        try{
            xmlhttp = new XMLHttpRequest();  
        }
        catch (e){
            try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");             
        }
            catch (e){
                try{
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");                 }
                catch (failed){
                      xmlhttp = false;  //如果失败则保证 request 的值仍然为 false。
                }
            }
        }
        return xmlhttp;
    }
    xmlhttp = CreateXMLHttp();
    xmlHttp.open("get","http://www.cnblogs.com",true);
    xmlhttp.onReadyStateChange = getResult;
    xmlhttp.send(null);
   function getResult(){
  if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
   alert(xmlhttp.responseText);
  }
 }
</script> 
haha
</body>
</html>

解决方案 »

  1.   

    你可以 再建个文件 随便命名,  用记事本打开 往里面写点内容 放在和当前html 同一路径下把
    xmlHttp.open("get","http://www.cnblogs.com",true);改成xmlHttp.open("get","fileName.xxx",true);就可以了
      

  2.   

     是不是要把这段代码改掉啊?怎么改啊?xmlHttp.open("get","http://www.cnblogs.com",true);
      

  3.   

    重新做个页面   在ASPX.CS做数据操作,在  xmlHttp.open("get","http://www.cnblogs.com",true);改成自己的页面路径就OK
      

  4.   

    不能在浏览器端直接使用AJAX来跨域访问资源,在服务器端是没有这种跨域安全限制的
    httpwebrequest抓取内容
      

  5.   

    xmlHttp.open("get","http://www.cnblogs.com",true)中的URL:"http://www.cnblogs.com"访问不到,新建一个页面,把这个路径替换掉。
      

  6.   

    这段代码是不是一定要写在服务器端啊?我现在的做法就是在电脑上建了一个html文件,然后在里面写了上面的代码.
      

  7.   

    下面是test.html<html>
    <head>
    </head>
    <body>
    <script type="text/javascript" language="javascript"> 
        var xmlhttp = false; 
        function CreateXMLHttp(){
            try{
                xmlhttp = new XMLHttpRequest();  
            }
            catch (e){
                try{
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
                }
                catch (e){
                    try{
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
                    }
                    catch (failed){
                          xmlhttp = false;  
                    }
                }
            }
            return xmlhttp;
        }
        xmlhttp = CreateXMLHttp();
        xmlHttp.open("get","test1.html",true);
        xmlhttp.onReadyStateChange = getResult;
        xmlhttp.send(null);
       function getResult(){
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
       alert(xmlhttp.responseText);
      }
     }
    </script> 
    haha
    </body>
    </html>
    下面是test1.html<html>
      <head>
      </head>
      <body>
        中国哈哈
       </body>
    </html>
      

  8.   

    这个基本的AJAX网上的代码很多。楼主你去网上找找看。
      

  9.   


    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" language="javascript"> 
        var xmlhttp = false; 
        function CreateXMLHttp(){
            try{
                xmlhttp = new XMLHttpRequest();  
            }
            catch (e){
                try{
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
                }
                catch (e){
                    try{
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
                    }
                    catch (failed){
                          xmlhttp = false;  
                    }
                }
            }
            return xmlhttp;
        }
        
       function getResult(){
      if(xmlhttp.readyState == 4){
        if(xmlhttp.status ==0 || xmlhttp.status == 200){
          alert(xmlhttp.responseText);
        }
      }
     }
    function getAjax()
    {
       xmlhttp = CreateXMLHttp();
        xmlhttp.open("get","test1.html",true);
        xmlhttp.onReadyStateChange = getResult;
        xmlhttp.send(null);
    }
    </script> 
    haha
    <input type='button' value='click me' onclick='getAjax();' />
    </body>
    </html>
      

  10.   


        xmlHttp.open("get","test1.html",true);
        xmlhttp.onReadyStateChange = getResult;
        
    改成
        xmlhttp.open("GET","test1.html",true);
        xmlhttp.onreadystatechange = getResult;javascript 是大小写敏感的http://www.mybuffet.cn
      

  11.   

    http://hi.baidu.com/bj%5Fkevin51/
    我这里收藏了点ajax视频,去找下,有你需要的,。
      

  12.   

    关键是这句
    if(xmlhttp.status ==0 || xmlhttp.status == 200){
    在本机的时候 xmlhttp.status 是 =0 的
      

  13.   


    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript" language="javascript"> 
        var xmlhttp = false; 
        function CreateXMLHttp(){
            try{
                xmlhttp = new XMLHttpRequest();  
            }
            catch (e){
                try{
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
                }
                catch (e){
                    try{
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
                    }
                    catch (failed){
                          xmlhttp = false;  
                    }
                }
            }
            return xmlhttp;
        }
        
       function getResult(){
      if(xmlhttp.readyState == 4){
        if(xmlhttp.status ==0 || xmlhttp.status == 200){
          alert(xmlhttp.responseText);
        }
      }
     }
    function getAjax()
    {
       xmlhttp = CreateXMLHttp();
        xmlhttp.open("GET","test1.html",true); 
        xmlhttp.onreadystatechange = getResult; 
        xmlhttp.send(null);
    }
    </script> 
    haha
    <input type='button' value='click me' onclick='getAjax();' />
    </body>
    </html>
      

  14.   

    test1.html 是和它 在一起么? 我这里 是没问题的你用的什么浏览器
      

  15.   

    HTMLPage1.htm 这个在vs2008下运行是没问题的<html>
    <head>
    </head>
    <body>
    <script type="text/javascript" language="javascript"> 
        var xmlhttp = false; 
        function CreateXMLHttp(){
            try{
                xmlhttp = new XMLHttpRequest();  
            }
            catch (e){
                try{
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
                }
                catch (e){
                    try{
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
                    }
                    catch (failed){
                          xmlhttp = false;  
                    }
                }
            }
            return xmlhttp;
        }
        
        xmlhttp = CreateXMLHttp();    xmlhttp.open("GET","test1.html",true);
        xmlhttp.onreadystatechange = getResult;
       
        
        xmlhttp.send(null);
        
       function getResult(){
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
       alert(xmlhttp.responseText);
      }
     }
    </script> 
    haha
    </body>
    </html>
    test1.html
    <html>  <head>  </head>  <body>  中国哈哈 </body> </html>
    不信试试这个连接
    http://www.mybuffet.cn/html/htmlpage1.htm
    http://www.mybuffet.cn