javascript - Titanium createHttpClient runs after other vars declarations -
i have code in titanium, calls php file on server print name of user match id:
var mystring; var request = titanium.network.createhttpclient(); var url = "http://localhost/myphp.php?id=1"; request.open("get", url, false); request.onload = function(){ var newstring = this.responsetext; ti.api.info(newstring); mystring = newstring; } request.send(); ti.api.info("result " + mystring);
titanium console prints me this:
- result undefined
- nameofuser
titanium seems call first code after request , request. can't change value of var responsetext. how can it? , why happens?
sorry if posted here before, not think in keywords search here in stackoverflow
thanks in advance =)
the request asynchronous, when call request.send()
not block execution. when request completes, onload
event handler invoked.
Comments
Post a Comment