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

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

1 Comment

That's not a JSON object. That's just an object.
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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.