Passing an Object to an $http POST in AngularJS

Problem

I am having some trouble with passing a parameter to a POST using $http in AngularJS

My Object Parameter:

var myObject = { 
  ID: 1, 
  ARRAYOFSTUFF: [
    {1, "Test", 3, "TestA"},
    {2, "XXX", 9, "DDDD"},
    {5, "TUUU", 6, "TeUUUU"}
  ]
}

So I call post like this:

$http({ method: "POST", url: MYURL_URL, params: myObject, cache: false });

It gets to my endpoint but the ARRAYOFSTUFF is null. I have tried changing this to use jQuery's $.param as below:

$http({ method: "POST", url: MYURL_URL, params: $.param(myObject), cache: false });

I think the issue here is caused because I cannot successfully pass the myObject.ARRAYOFSTUFF around. I have passed arrays before in $http POSTs but never with an object like this.

I did change my endpoint to pass only the ARRAY but I have the same problem that when it got to the endpoint it was null.

Thanks for any help in advance.

Problem courtesy of: cododromo

Solution

Change params to data:

$http({ method: "POST", url: MYURL_URL, data: myObject, cache: false });
Solution courtesy of: Phil Sandler

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.