先贴一段代码var xmlHttp=new XMLHttpRequest()
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
alert(xmlHttp.responseText);
alert(xmlHttp.responseText.length);
}
}
xmlHttp.open("GET","http://m.weather.com.cn/data/101120605.html",true);
xmlHttp.send(null);
}
我所遇到的问题:
IE下正常
Firefox里xmlHttp.responseText 是空值
请求站内页面的情况下不会出现这种情况

解决方案 »

  1.   

    firefox下用firebug直接看 访问返回的结果
      

  2.   

    的确是跨域了。如果数据时jsonp的话,所有的浏览器都可以。参见:
    http://stackoverflow.com/questions/4472051/jquery-json-request-gets-a-200-ok-answer-but-no-content
    Accept application/json, text/javascript, */*; q=0.01
    Accept-Encoding gzip, deflate
    Accept-Language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
    Connection keep-alive
    Host m.weather.com.cn
    Origin http://localhost
    Referer http://localhost/test.php
    User-Agent Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0
      

  3.   

    ie本地浏览测试可以跨域,firefox等跨域不了ie通过http也跨域不了。
      

  4.   

    那请问大家在用JS加载别人提供的API都用什么方法
      

  5.   

    动态加载<script>标签进行跨域访问。
    例如:
    function loadData() {
        var url = "http://tweeter.com/api/?callback=updateTweets";
        var newScriptElement = document.createElement("script");
        newScriptElement.setAttribute("src", url);
        newScriptElement.setAttribute("id", "jsonp");
        var oldScriptElement = document.getElementById("jsonp");
        var head = document.getElementsByTagName("head")[0];
        if (!oldScriptElement) {
            head.appendChild(newScriptElement);
        }
        else {
            head.replaceChild(newScriptElement, oldScriptElement);
        }
    }
    或者使用jquery提供的包装。
      

  6.   

    7楼callback=updateTweets,那个就是jsonp了,当然可以跨域了。