How do I POST a network of objects with Jquery?

advertisements

Is this even possible? I've been searching and reading for hours and 99% of the posts are about JSON. I just have an object array I want to POST, nothing special.

var arr = [];
arr.push({"name":"steve", "age":35});
arr.push({"name":"sam", "age": 25});

on the other end (node.js), I get this:

{ steve: '', sam: '' }

I'd be incredibly happy to get something similar to

[{"name":"steve", "age":35},
{"name":"sam", "age": 25}]

I feel like I'm missing something incredibly simple, because this seems trivial. I'm not constructing the array myself and this is the format I receive it in. I figured it would be something I could just throw into an $.ajax() post and grab it on the other side.

I've tried so many different combinations of the ajax call

$.ajax({
    method: "POST",
    data: theArray,
    url: someAddress
})

with type instead of method, contentType, dataType, etc, etc with no luck. Spent a whole bunch of time on http://api.jquery.com/jQuery.ajax/ but everyone wants to send JSON. I tried JSON.stringify() on the client, but JSON.parse()on the server side results in giving me data just like my "on the other end..." example above.


Try something

   $.ajax({
        url: "testcookie.php",
        type: "POST",
        data: {
            'arr[]': JSON.stringify(arr)
        }
    });