For example in this case
I would like to call url1, call url2, call url3; , step by step after waiting for previous call back.
For example this is my source code
var pram={};
var url = "http://myapiserver.com/api/test";
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("first call is success!!");
var url2 = "http://myapiserver.com/api/test2";
var client2 = Ti.Network.createHTTPClient({
onload : function(e) {
// call URL 3 here!!
Ti.API.info("second call is success!!");
},timeout : 3000
});
client2.open("GET", url);
client2.setRequestHeader('Content-type','charset=utf-8');
client2.send(pram2);
},
timeout : 3000
});
client.open("GET", url);
client.setRequestHeader('Content-type','charset=utf-8');
client.send(pram);
This source code is OK however, if you need more steps, nest structure will be deeper and deeper and difficult to maintenance.
Is there good way to clean this kind of source code??