7

Is there a easy way to build an ajax query like this with jquery?

http://www.test.com/?value=happy&value=good&value=day

I tried

$.getJSON('http://www.test.com/', {'value': ['happy','good','day']});

but the result becomes http://www.test.com/?value[]=happy&value[]=good&value[]=day

5
  • There's no logic in that kind of request. How would you access each and every value if they all have the same key? Commented Aug 11, 2012 at 15:19
  • it can be access. for example, I am using google appengine and there is a function called get_all developers.google.com/appengine/docs/python/tools/webapp/… Commented Aug 11, 2012 at 15:26
  • 1
    @OfirBaruch On the server-side you'd get an array of the values. Commented Aug 11, 2012 at 15:26
  • 1
    I'd also like to get rid of the brackets… Commented Jul 8, 2013 at 4:39
  • No logic in that kind of request? That's the HTML standard way of passing values from a 'select mutiple'. The 'select' tag has only one name (e.g. 'fieldname'), and so when multiple values are selected, they come through exactly like that... 'fieldname=1&fieldname=2&fieldname=3'. In ASP.NET MVC controller, those values would come in as a string array in a parameter named 'fieldname'. If you made 'fieldname' parameter a string instead of an array, then MVC would just join them all into a single comma-separated string with all the values for 'fieldname'. Commented Mar 30, 2016 at 4:54

2 Answers 2

6

Just for anyone who comes here through search, you can use the traditional parameter to $.ajax and set it to true then you will get:

http://www.test.com/?value=happy&value=good&value=day.

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

Comments

-1

This url seems to be good:

http://www.test.com/?value[]=happy&value[]=good&value[]=day

in php you can access the values like an array

2 Comments

Who care about what PHP does? I don't want square brackets in my requests, how can I build such a request with jQuery?
Like @alartur said, that's work for PHP for sure, but totally doesn't for ASP.

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.