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
Try alert(data.name);
instead. You can check what's actually returned from browser debug eg press F12 in Chrome and set a breakpoint in the JS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.