这是html / javascrpt文件中的代码:
var console = console ||
{log:function(msg){window.runtime.trace(msg);}};
function waitToFinish(){
console.log("this is wait to finish loading the url");
console.log(this.readyState);
console.log(this.status);
if(this.readyState != 4){
return;
}
console.log("readystate is 4");
console.log("response text length is:"+this.responseText.length);
if (this.status === 200 || this.status == 304) { // status is allways 0
console.log("success");
console.log("response text length is:"+this.responseText.length);
}
}
function openURL(url){
console.log("opening link:"+url);
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url
,true);
xmlhttp.onreadystatechange
=waitToFinish;
xmlhttp.send(null);
return false;
<input type=button onclick="openURL('http://www.yahoo.com');" value="click me" />
}
这是空中输出:
opening link:http://www.yahoo.com
this is wait to finish loading the url
4
0
readystate is 4
response text length is:0
这是firefox中激活了forcecors插件的输出:
opening link:http://www.yahoo.com
GET http://www.yahoo.com/ 200 OK 4.3s
this is wait to finish loading the url
1
0
this is wait to finish loading the url
2
200
this is wait to finish loading the url
... a bunch of times readystate change is called
this is wait to finish loading the url
4
200
readystate is 4
response text length is:317163
success
response text length is:317163
在空中onreadystate被调用一次,就是这样,状态立即为4但状态保持为0且responseText为空。
http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7eb3.html
显示xmlhttprequest仅检查readystate的示例,但如果我这样做,则responseText每次都是空的。同步请求有效,但异步不是
答案 0 :(得分:0)
在Windows上使用IE,所以当我的IE设置为脱机工作时,我的请求发生了奇怪的事情。有些是好的,因为它们在缓存中,有些会失败。
将IE设置为在线工作,一切都正常“正常”。