Return array from createHTTPClient
I am using createHTTPClient to make a call to a php file that authenticates a user. I can return a string of text, but is it possible to return an array?
7 Answers
-
How is this question any different than the one I answered the other day? That example shows how PHP can return an array and then you can turn that into an object in javascript.
http://developer.appcelerator.com/question/68461/return-data-from-php
-
No problem, let me know if it helps
-
If you define the response object/variables outside of any functions or objects, its scope should be global.
Let's say this is in app.js
var login_response; loginReq.onload = function(){ var json = this.responseText; login_response = JSON.parse(json); }
See how login_response has its var defined outside the function? This should put that var in the global scope and will be available to all other JS files.
But this would not be available to other files because it was defined in the scope of the function
loginReq.onload = function(){ var json = this.responseText; var login_response = JSON.parse(json); }
And yes.. I agree. The Q/A is awkward. If this were forums we could split things up by platform, etc. and it would be easier to move around.
-
I have a file I call defaults.js and I have an object that I create in there and it holds all the different settings and info. It is one of the first files I include so it gets that object into the global scope and then I have about 20 other JS files that access the global object I created.
-
Sorry, I did not see your response, my bad.
-
This Q&A system is pretty confusing. I wish they would use just a normal forum. I tried what you suggested in the other thread and it works great. Is their a way I can make those vars global? Just so I can access them from any js file? Or at least pass it back to the app.js file and then pass them to the windows I need…hope that makes sense.
-
Awesome man I really appreciate the help. I was thinking if I defined it outside of the function, it would still only be available to the current JS file.