Titanium Community Questions & Answer Archive

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

Loading TableView data from external file

Hello,

I've been given the task to create an app showing recently acquired products by a shop. This is my first iPhone app, so I'm not that familiar with the Titanium UI, I am however familiar with JavaScript.

Thanks to Titanium Appcelerator, this seems pretty easy. I have, however, one problem. At the moment, my product list is an array like the following:

var ProductArray = [];

ProductArray.push({
    "id":ProductArray.length,
    "name":"Product 1 Name",
    "description":"Product 1 Description",
    "image":"dev/gold_ring.png",
    "date":"Product 1 Date"
});

ProductArray.push({
    "id":ProductArray.length,
    "name":"Product 2 Name",
    "description":"Product 2 Description",
    "image":"dev/silver_ring.png",
    "date":"Product 2 Date"
});

Now, what I would like, is my array to be given from a PHP script on the web in some sort of JSON format - how can I do that?

I've tried using an XMLHttpRequest but without luck.

Any thoughts?

Caspar

— asked July 24th 2010 by Caspar Jespersen
  • json
  • tableview
  • xml
0 Comments

3 Answers

  • Accepted Answer

    var xhr = Ti.Network.createHTTPClient();
    
        xhr.onerror = function(e) {
                alert(e.rrror)
    
        };
    
        xhr.onload = function() {
                  var data = JSON.parse(this.responseText);
                  TI.API.info(data);   
        };
    
        xhr.open('POST', someremoteurl);
    
        xhr.send({var1:var1value,var2:var2value});
    
    — answered July 25th 2010 by Daniel Lim
    permalink
    0 Comments
  • On the server side you have json_encode/json_decode functions ( php ). You can use this to return a valid json string .

    With the reply you get ( needs to be a valid json string ) you can build custom rows for your table.
    Here is a tutorial on how todo it.

    http://cssgallery.info/custom-row-for-tableview-in-appcelerator-titanium/

    — answered July 24th 2010 by Dan Tamas
    permalink
    1 Comment
    • Hi Tamas,

      Sorry for not making myself clear.
      My problem is not to make the interface nor the PHP - I can do that. My problem is how I load the contents of my PHP file into my app.js?

      Caspar

      — commented July 24th 2010 by Caspar Jespersen
  • What I was looking for, was this: http://developer.appcelerator.com/question/28521/thought-i-would-share-some-code-remote-ajax-call-thats-more-jquery-like

    — answered July 25th 2010 by Caspar Jespersen
    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.