问题描述:在使用Ajax提交数据后,后台方法没有返回视图。
解决方法:
示例代码:
@RequestMapping(value = "/ajaxSubmit", method = RequestMethod.POST)
public ModelAndView ajaxSubmit() {
    // 处理逻辑...
    ModelAndView modelAndView = new ModelAndView("viewName"); // 设置视图名称
    // 设置需要传递给视图的数据
    modelAndView.addObject("data", data);
    return modelAndView;
}
@RequestMapping(value = "/ajaxSubmit", method = RequestMethod.POST)
public String ajaxSubmit() {
    // 处理逻辑...
    return "viewName"; // 返回视图名称
}
spring.thymeleaf.prefix=classpath:/templates/ # 设置视图文件的路径前缀
spring.thymeleaf.suffix=.html # 设置视图文件的后缀
上述代码示例中的"viewName"即为视图文件的名称,视图文件路径为classpath:/templates/viewName.html。
注意:确保在Ajax请求中正确处理返回的视图结果。可以使用success回调函数处理返回的数据,例如使用jQuery的ajax方法:
$.ajax({
    url: "/ajaxSubmit",
    type: "POST",
    data: data,
    success: function(response) {
        // 处理返回的视图结果
        $("#result").html(response); // 将视图结果显示在页面元素中
    },
    error: function(xhr, textStatus, errorThrown) {
        // 处理错误
    }
});