先贴一段代码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 是空值
请求站内页面的情况下不会出现这种情况
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 是空值
请求站内页面的情况下不会出现这种情况
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
例如:
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提供的包装。