0

as per api request i must send data categories: [1,2,3,4]

I have tried

data: {
      categories: [1,2,3,4]
}

But it gets sent as

categories[]:1
categories[]:2
categories[]:3

Not as ategories: [1,2,3,4]

How can i send an array of numbers in angularjs $http method

categories: [1,2,3,4]

8
  • Why you say it gets sent as categories[]:1 categories[]:2 categories[]:3 and not as [1,2,3,4]? Are you checking it in the backend service and it is arriving like this? Commented Jul 17, 2017 at 15:29
  • How are you sending it? How are you testing it? Please provide more information. Commented Jul 17, 2017 at 15:30
  • @lealceldeiro when inspecting chrome network tab, i see the Form Data Commented Jul 17, 2017 at 15:32
  • the way it gets send now, it should arriving in backend as array, if you want it to be as a string just '[' + [1,2,3,4].join(',') + ']' Commented Jul 17, 2017 at 15:32
  • Look at this example it doesn't seems to be a problem to send an array in a PUT Commented Jul 17, 2017 at 15:34

1 Answer 1

1

Finally i have found the answer to my question after alot of research https://github.com/angular/angular.js/issues/3121

I should have sent it as "categories[]": [1,2,3,4]

not as categories = [1,2,3]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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