首页 > 解决方案 > 对弹簧控制器的 Ajax 调用未返回成功

问题描述

我正在使用带有参数的ajax post到spring mvc控制器,数据绑定良好但没有返回成功。响应将转到另一个页面。

我正在从模态调用 ajax,并且需要将成功消息返回到相同的模态中。

以下是我的ajax调用,

$.post({
url : 'saveEmployee',
data : $('form[name=employeeForm]').serialize(),
processData: false,
success: function (resp) {
    alert("hello");
},
failure: function (resp) {
    alert("hello1");
}
})

以下是我的控制器代码,

@RequestMapping(value="/saveEmployee", method = RequestMethod.POST)
@ResponseBody
public void Insert(ModelMap model, Principal principal,HttpSession session,@ModelAttribute @Valid Profile profile,
         BindingResult result) {
    System.out.println("profilec "+profile.getRashi());

}

数据绑定得很好,但是,空页面作为响应返回,成功响应需要返回到相同的模式。

标签: ajaxspring-mvc

解决方案


推荐阅读