0

Is there any built-in solution for posting array of objects, through jquery?

The array is

data = [{
  id: "333",
  date: "22/12/2015"
 },
{
  id: "333",
  date: "22/12/2015"
 }]

$.post('url', data, function(){}, "json"); failed

yossi
  • 3,090
  • 7
  • 45
  • 65

2 Answers2

1

You can send an object that contains the array like this:

data = {
    items: [{
      id: "333",
      date: "22/12/2015"
    },
    {
      id: "333",
      date: "22/12/2015"
    }]
}

$.post('url', data, function(){}, "json");
Diego
  • 16,436
  • 26
  • 84
  • 136
0

You need to pass values in a POST as key/value pairs. You can't just send the array, you need to give it a "key" in the POST array.

$.post('url', {data: data}, function(){}, "json");
gen_Eric
  • 223,194
  • 41
  • 299
  • 337