Titanium Community Questions & Answer Archive

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

XHR send multi-dimensional array

Hi,

Just wondering why single arrays are sent fine using createHTTPClient() and complex arrays aren't. Am I doing something wrong? Here is what I am doing:

Works fine:

var xhr = Titanium.Network.createHTTPClient();
xhr.open("POST",'http://api.com/names);
//code here
xhr.send({name:'Jim'});

Doesn't work at all:

var xhr = Titanium.Network.createHTTPClient();
xhr.open("POST",'http://api.com/names);
//code here
var names = new Array();
names.push({name: 'Jim Bob', DOB:'29-06-1985'});
names.push({name: 'Sam Smith', DOB:'15-02-1972'});
xhr.send(names);

And at the server end I have a RESTful API that's just printing out the $_POST vars to see whats coming through.

The second options just prints a blank $_POST response where the other doesn't. It comes out fine. Why wont my complex array?

Anyone see what I might be missing?

Ian

— asked June 28th 2010 by Ian Briggs
  • iphone
  • xhr
0 Comments

2 Answers

  • i think to be able to send multidimensional arrays, you have to json-encode them and send it as you do in your working example

    — answered June 28th 2010 by Christian Sigl
    permalink
    0 Comments
  • Ahh I see. Would you have an easy way to do that with Titanium that you know of?

    — answered June 28th 2010 by Ian Briggs
    permalink
    1 Comment
    • var obj = JSON.stringify(names);

      xhr.send({names: obj});

      — commented June 28th 2010 by Christian Sigl
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.