Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked October 11th 2010 by Ronnie Swietek
  • array
  • createhttpclient
  • return
0 Comments

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

    — answered October 11th 2010 by John McKnight
    permalink
    0 Comments
  • No problem, let me know if it helps

    — answered October 11th 2010 by John McKnight
    permalink
    0 Comments
  • 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.

    — answered October 11th 2010 by John McKnight
    permalink
    0 Comments
  • 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.

    — answered October 11th 2010 by John McKnight
    permalink
    0 Comments
  • Sorry, I did not see your response, my bad.

    — answered October 11th 2010 by Ronnie Swietek
    permalink
    0 Comments
  • 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.

    — answered October 11th 2010 by Ronnie Swietek
    permalink
    0 Comments
  • 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.

    — answered October 11th 2010 by Ronnie Swietek
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.