我在我的 Java spring boot 应用程序中有一个简单的 ajax 调用,它调用控制器中的一个方法,然后将值返回到前端控制台。但是,当我运行代码时,它以状态运行,400
但在我的控制台中没有显示任何内容。不确定我是否忘记了任何东西或者我的设置错误,但我假设没有任何东西被传回。
查询:
$(".modalPathContentBtn").on("click", function(event) {
getSecondQuery();
});
function getSecondQuery() {
var search2 = {
"dtoTiername" : "Test"
}
$.ajax({
type : "POST",
contentType : 'application/json; charset=utf-8',
dataType : 'json',
url : "/ajax/mqlGetSecondQuery",
data : JSON.stringify(search2),
success : function(result) {
console.log("It works: " + result);
}
});
}
爪哇:
@RequestMapping(value = "/ajax/mqlGetSecondQuery", method = RequestMethod.POST)
public @ResponseBody String sendSecondQuery(@RequestBody TestApp mTestApp, HttpServletRequest request) {
String pathVal = mTestApp.getDtoTiername();
System.out.println("Test of if it is getting to this part of the code");
return "randomString";
}