The question is in the title. I make a request with Titanium.Network.HTTPClient
assuming the result of the call is (ty var_dump) : array(2) { [0]=> string(3) "Foo" [1]=> string(3) "Bar" }
EDIT : here is the complete function.
var paramsrecepteur = "demande=recepteur";
var client = Ti.Network.createHTTPClient({
// si la réponse est ok
onload : function(e) {
Ti.API.info("**************************************");
var results = JSON.parse(this.responseText);
Ti.API.info(results[0]);
Ti.API.info("**************************************");
},
// si erreur . ou timeout !
onerror : function(e) {
alert("erreur recepteur");
},
timeout : 5000 // implique un probleme reseau
});
Ti.API.info("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤");
Ti.API.info(url); // url is defined upper & is correct.
Ti.API.info("¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤");
client.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
client.setRequestHeader("Content-length", paramsrecepteur.length);
client.setRequestHeader("Connection", "close");
client.open("POST", url, true);
client.send(paramsrecepteur);
EDIT 2 : be carefull that you send a JSON object, and not a php array as i do ...
Thinqs.
You just have the wrong variable names. The proper way to get any of these is shown below:
var client = Ti.Network.createHTTPClient({
onload : function(e) {
// Print anything you get back
Ti.API.info(this.responseData);
Ti.API.info(this.responseXML);
Ti.API.info(this.responseText);
// Parse your results
var results = JSON.parse(this.responseText);
Ti.API.info(results[0]); // Print first index of the array
}
});