ashu
ashu

Reputation: 1359

jquery post function with array as parameter

i have to pass a array of values to a jsp page. i am using the following jquery function

$.post("add.jsp" ,{'URL_Arr': urlarray}, function (data) {   
    alert(urlarray);
    $('#einfo').html(data);
});

where, urlarray is an array.Alert shows me the (urlarray)array values as 48,39,28

And add.jsp page conatains the following

String URL_Arr1=request.getParameter("URL_Arr");
out.println("arr:"+URL_Arr1);

Am getting the URL_Arr as null

Can any one help me in passing the array values to another jsp page using jquery post.

Upvotes: 1

Views: 3932

Answers (1)

BalusC
BalusC

Reputation: 1108742

For arrays, jQuery will suffix the parameter name with [], so use URL_Arr[] as parameter name. You should also be using getParameterValues() to get all array values. The getParameter() would only return the first item.

Summarized:

String[] urlarray = request.getParameterValues("URL_Arr[]");
// ...

Upvotes: 5

Related Questions