本文介绍了无法从Adobe AIR的xmlhtt prequest响应状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在code在HTML / javascrpt文件:

This is the code in the html/javascrpt file:

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" />
}

下面是在空气中的输出:

Here is the output in air:

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插件启动:

This is the output in firefox with forcecors plugin activated:

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的是空的。

In air onreadystate is called once and that's it, state is immediately 4 but status stays 0 and responseText is empty.

http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7eb3.html

显示了xmlhtt prequest仅供readyState的检查一个例子,但如果我这样做了的responseText是空的所有的时间每次。 Synchronyous申请工作,但异步不

Shows an example for xmlhttprequest checking only for readystate but if I do that the responseText is empty all the time every time. Synchronyous requests work but async doesn't

推荐答案

在Windows AIR使用IE浏览器,所以当我的IE浏览器被设置为脱机工作我有奇怪的事情发生的请求。有些是好的,因为他们在高速缓存中,有些会失败。

On Windows AIR uses IE so when my IE was set to work offline I had strange things happen with the request. Some were ok as they were in cache and some would fail.

设置IE浏览器的在线工作,一切工作正常了。

Set IE to work online and everything was working "normal" again.

这篇关于无法从Adobe AIR的xmlhtt prequest响应状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 13:45