我正在对 Spring Controller 进行看似极其简单的 ajax 调用。它很好地击中了 Controller ,并且 println 被打印出来,但我从未进入 AJAX 成功函数。有什么想法吗?
我的 AJAX 调用:
$.post(SERVER_LOC, function(){
alert("success!");
});
我的 Spring Controller :
@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void home(String s) {
System.out.println("In the controller!");
}
最佳答案
将 Controller 方法更改为:
@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseBody //this will parse the returned Object to JSON
public String/*or some other type*/ home(String s) {
System.out.println("In the controller!");
return "something";
}
关于java - 对 Spring MVC 的 AJAX 调用有效,但未命中成功函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24807068/