2

I have the following jquery:

  var xj=[{"name":"person","id":1},{"name":"jack", "id":2}];
  $.post('/hex-jt/locations',xj , function(data){
    console.log("this posted");
  },'json');

which seems like it should be ok. But it is passed like this to my rails app:

enter image description here

Any idea what is going on with this?

guido
  • 18,864
  • 6
  • 70
  • 95
timpone
  • 19,235
  • 36
  • 121
  • 211
  • 2
    any error in the console? – Arun P Johny Sep 07 '13 at 01:33
  • 1
    Instead of an image, please give us the complete text of the error in the post. A person who searches on Google won't be able to find the text of your error if it's in an image. – George Stocker Sep 07 '13 at 01:33
  • 1
    why close? what the OP posted is enough to answer. jquery.post() wants a PlainObject while he is passing an array: http://api.jquery.com/Types/#PlainObject – guido Sep 07 '13 at 01:44

1 Answers1

1

You are calling jquery.post() with bad argument data, passing an array instead of a String or a PlainObject.

jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

data
Type: PlainObject or String
A plain object or string that is sent to the server with the request.

You can for instance modify it like this, wrapping the array in an object:

xj={"users":[{"name":"person","id":1},{"name":"jack", "id":2}]};
guido
  • 18,864
  • 6
  • 70
  • 95
  • thx, I had noticed when I wrapped it, it worked; didn't realize it was a requirement. Live an learn. – timpone Sep 07 '13 at 02:18