Reputation:
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.
Upvotes: 1
Views: 9176
Reputation: 28016
Change params
to data
:
$http({ method: "POST", url: MYURL_URL, data: myObject, cache: false });
Upvotes: 7