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 data from PHP

Hey quick question. I have a basic auth form working right now. Right now it is just sending a string "success" when login is successful and "false" when it is not. When its successful I want to return the users data like first name, last name, address etc. How can I do that?

I am using the createHTTPClient() to do the authentication through a php file right now.

— asked October 8th 2010 by Ronnie Swietek
  • array
  • data
  • of
  • php
  • return
0 Comments

3 Answers

  • I use Jquery && JSON. If the login is successful, PHP will return a JSON array with all the users info, if it isn't successful, it returns a json array [false]

    $.ajax({type: "GET",url: 'YOURURL',data: string,timeout: 10000,success: function(res) {
    yourcode
    });
    
    — answered October 8th 2010 by Bryce Wilkinson
    permalink
    1 Comment
    • Hey John,
      I understand that and that is already working for me. Rather than returning a string of text, I'd like to return an object array or something similar.

      — commented October 8th 2010 by Ronnie Swietek
  • This should work

    loginReq.onload = function(){
        var your_response = this.responseText;
    }
    
    — answered October 8th 2010 by John McKnight
    permalink
    2 Comments
    • Hey John, I understand that and that is already working for me. Rather than returning a string of text, I'd like to return an object array or something similar.

      — commented October 8th 2010 by Ronnie Swietek
    • Gotcha…

      In PHP you could say something like this:

      <?php
      $response = array('loggedin' => true, 'someotherdata' => 'test');
      echo json_encode($response);
      ?>
      
      
          var json = this.responseText;
          var response = JSON.parse(json);
      
          alert(response.loggedin);
          alert(response.someotherdata);
      

      This would read in the text and return a variable called response the would be an array/object assuming your PHP returned some JSON.

      — commented October 8th 2010 by John McKnight
  • well what I am using is pretty easy. I dont want to bring in jquery. Does my method only return text?

    loginBtn.addEventListener('click',function(e)
    {
        if (username.value != '' && password.value != '')
        {
            loginReq.open("POST","http://localhost:8888/post_auth.php");
            var params = {
                username: username.value,
                password: Ti.Utils.md5HexDigest(password.value)
            };
            loginReq.send(params);
        }
        else
        {
            alert("Username/Password are required");
        }
    });
    
    — answered October 8th 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.