1

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.

1 Answer 1

7

Change params to data:

$http({ method: "POST", url: MYURL_URL, data: myObject, cache: false });
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, how silly of me. Tried that and it works! I will accept the answer shortly (When Stack Overflow will let me!)

Your Answer

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