I have a code that works great on iPhone, but when it comes to make it run on Android, it ignores some parts.
The problem is that I have nested createHTTPClient calls:
var xhr1 = Titanium.Network.createHTTPClient();
xhr1.open('GET',url1);
xhr1.send();
xhr1.onload = function(e) {
var list1 = JSON.parse(this.responseText);
var list1Length = list1.length;
Titanium.API.info('list1 length : ' + list1Length);
var fctForList2 = function(argument){
var xhr2 = Titanium.Network.createHTTPClient();
xhr2.open('GET',url1);
xhr2.send();
xhr2.onload = function(e) {
// display list where a value corresponds to the argument
var list2 = JSON.parse(this.responseText);
var list2Length = list2.length;
Titanium.API.info('list2 length : ' + list2Length);
};
};
var argument = list1[0].someValue;
fctForList2(argument);
};
So in the code above, I found a workaround that runs great on iPhone.
As you know, the synchronous mode can’t be forced (even if the documentation mentions that it can be done) so I have used this method to call the second xhr synchronously.
But why the list2Length is null with Android?
PS: I work under OSX with the Titanium SDK 1.6. For my tests on Android, I use the emulator (API 2.2) and a device (2.1update1).
Thanks,
Regards.
i would do it like that:
for what is the “argument”?
you need to declare the onload function before calling the .open and .send method.