0

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?

0

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

in .js(java script)

var variable="test";
$.ajax({
    url: baseUrl + "nameController/test1",
    async: false,
    data: {val: variable},
    dataType: 'html',
    success: function (dat) {
        console.log(dat);
    }
});

you create nameController.java

@RequestMapping(value = "test1", method = RequestMethod.POST)
public @ResponseBody
String checkRoomStatusReservation(@RequestParam(value = "val", required = true) String parse) {
    System.out.println("parse"+parse);
    //value from parse=test
return parse;
}

you can try this

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.