1

I want to pass a query like that to the server:

/rest/articles/getTexts?tagIds[]=1&tagIds[]=88

I can do it with $.param like this:

var tagIds = [1, 88]
var param = $.param({tagIds: tagIds});

I've tried the same with angular:

var tagIds = [1, 88]
$http.get(serverUrl + "articles/getTexts" + {params:{tagIds: tagIds }})

But it produced the string like this:

/rest/articles/getTexts?tagIds=1&tagIds=88

Note the square brackets missing which leads to ovveriding of tagIds parameter on server side instead of making an array of it like in the case with jquery's param. Am I using angular's params in the wrong way or it's not possible to achieve what I want?

5
  • But this '/rest/articles/getTexts?tagIds=1&tagIds=88' is standard way to pass array in query string Commented Apr 18, 2015 at 16:42
  • Have you tried params :{ tagIds: JSON.stringify(tagIds) } ? Commented Apr 18, 2015 at 16:43
  • @salniro, this puts as a string instead of an array of values for a param. Commented Apr 18, 2015 at 16:51
  • @PetrAveryanov, I guess it depends on how server side interprets them in such form. PHP ovverrides. Commented Apr 18, 2015 at 16:51
  • Visit stackoverflow.com/questions/47217941/… Commented Aug 26, 2019 at 10:04

1 Answer 1

3

Not tested, but if you want the param name to be tagIds[], then that's also what the key of the params object should be:

params:{'tagIds[]': tagIds }
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.