I would like to send JavaScript array to servlet using jQuery $.ajax.
var json=[1,2,3,4];
$.ajax({
url:"myUrl",
type:"POST",
dataType:'json',
success:function(data){
// codes....
},
data:json
});
When I use
request.getParameter("json");
request.getParameterValues("json");
It returns null.
How can I access the values?
Send array as value of JS object so you end up as
{json:[1,2,3,4]}.In servlet, you need to suffix the request parameter name with
[].jQuery appends them in order to be friendly towards weak typed languages like PHP.