How do you send an array as part of an (jquery) ajax request
- by Ankur
I tried to send an array as part of an ajax request like this:
var query = [];
// in between I add some values to 'query'
$.ajax({
url: "MyServlet",
data: query,
dataType: "json",
success: function(noOfResults) {
alert(noOfResults);
}
});
}
I wanted to see what I get back in the servlet, so I used this line:
System.out.println(request.getParameterMap().toString());
Which returned {} suggesting an empty map.
Firebug tells me I am getting a 400 bad request error
If I send a queryString like attribute=value as the 'data' then everything works fine, so it has to do with not being able to send an array as is. What do I have to do to get that data into the servlet for further processing. I don't want to pull it out and turn it into a queryString in the JS if I can avoid it.
EDIT: I used the .serializeArray() (jQuery) function before sending the data. I don't get the 400 but nothing useful is being sent through.