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
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
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
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
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.
Set IE to work online and everything was working “normal” again.