views:

27

answers:

2

I have a servlet that needs a call like http://localhost:8080?a=1&a=3&a=2&b=5. The thing is it has multiple params with the same name like 'a' here. How can I generate such a servlet query. I used this for distinct param names.

$.ajax({
  url: 'http://localhost:8080',
  data: {a: 1, b: 2, c: 3},
  success: function(response) {
  }
});

But what can I do when the param names are not distinct? I need the outgoing GET to look like shown above and not in some serialized format for it to be compatible with the servlet (which I cant modify)

Thank you for you help

+1  A: 

You can just pass the ajax data option as a string, So in your case you want

$.ajax({
  url: 'http://localhost:8080',
  data: "a=1&a=3&a=2&b=5",
  success: function(response) {
  }
});

How you go about defining that string I'll leave to you :)

EDIT: Formatting

RueTheWhirled
I confirm that this works and I can also confirm that it is clever :)
+1  A: 

Check out the "traditional: true" flag in the jquery.ajax documentation. I've had to set it to true when I've had multiple form fields with the same name and it wasn't playing nice with MVC2.

Jeff T
RueTheWhirled