最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing an Object to an $http POST in AngularJS - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Jun 12, 2014 at 14:38 janSO 356 bronze badges asked Jun 12, 2014 at 14:33 user227466user227466
Add a ment  | 

1 Answer 1

Reset to default 7

Change params to data:

$http({ method: "POST", url: MYURL_URL, data: myObject, cache: false });
发布评论

评论列表(0)

  1. 暂无评论