<html>
<body>
<script type="text/javascript">
    var xmlHttp;
    function createXMLHttpRequest(){
        try{
            xmlHttp=new XMLHttpRequest();
        }
        catch (e){
            try{
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e){
                try{
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e){
                    alert("您的浏览器不支持AJAX!");
                    return false;
                }
            }
        } 
    }
    function GetURL(url){
        createXMLHttpRequest();    
        xmlHttp.onreadystatechange=function(){
            if(xmlHttp.readyState==4){ 
                if(xmlHttp.status==200){
                    alert('存在')
                }
                else{
                    alert('不存在')
                }
            }
        }
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);    
    }
</script><input type="button" onclick="GetURL('http://www.baidu.com/')"  value="http://www.baidu.com/ 存在吗?"></input>
<input type="button" onclick="GetURL('http://www.error.com/')" value="http://www.error.com/ 存在吗?"></input>   
</body>
</html>这个 在ie下 没问题,不知道为什么在ff下 baidu 为不存在求解。 

解决方案 »

  1.   


    跨域了?
    那怎么 ie 和ff效果不一样?
      

  2.   

    xmlHttp.status 在火狐下返回值是为0你创建xmlhttp 出错了.
      

  3.   

    应该是URL的问题,原因不清楚
      

  4.   

    用jquery封装好的 就ok了,自己写太麻烦了
      

  5.   

    跨域,如果你想解决的话可以使用代理:
    在你的域下面写一个xx.php,接收一个url,然后在这个php中判断是否存在这个网址,再返回给js。也就是说,js请求的是本域的php页面,php请求外域的内容并将结果返回给js。
      

  6.   

    我也想知道。在ff中输入地址,也是get方法  为什么可以;用ajax也是get方法  为什么跨域了就不可以;
    IE可以设置浏览器安全 也可以设置跨域;