Rouz Rouz - 7 months ago 9
Javascript Question

Ajax POST data array is always empty

I am having a slight problem with ajax and Java servlet.

$.ajax({
url: 'sampleURL',
type: 'POST',
data:data,
success: function(response){ },
error: function(){}
});


My data object is made like this

{name:'name',vars:[array]}


My vars array exists, and is not empty.

When i try to do this thing in servlet

System.out.println(request.getParameter("name")); //it does print name


But when I try to print parameter vars it is always null.

Where did I go wrong?

Answer

Well It is a bit weird for this to be needed but if I created object like this

{name:'name',JSON.stringify(vars:[array])}

Param vars is not null anymore and I can use it as JSON

Comments