Reputation: 2550
In my application I want to pass a object back to the jsp file using ajax.
JSP file
function getval(sel) {
jq(function() {
jq.post("/spring-mvc-jquery/krams/main/ajax/add", {
inputNumber3 : jq(sel).val()
}, function(data) {
alert(data.getName);
});
});
}
Controller
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody
Person view(@RequestParam(value = "inputNumber3", required = true) Integer inputNumber3) {
logger.debug("Input number recieved: " + inputNumber3);
return new Person("John", 22);
}
But in the allertbox i cant get the Person's object values. In the code I want to see the alertbox showing John
. But it shows 'unspecified'. If I return a int value(25) instead of person object, it shows successfully.
Please help. Answers in the other questions didn't help
Upvotes: 0
Views: 1193
Reputation: 57381
Try alert(data.name);
instead. You can check what's actually returned from browser debug e.g. press F12 in Chrome and set a breakpoint in the JS.
Upvotes: 1