前端ajax用POST方式:
$.ajax({
type : "POST",
url : "**/save.do",
async : true,
dataType : "json",
data : "data=中文",
success : function(resp) {
alert(resp.cr); //必须严格按照JSON的标准来
},
error : function() {
alert('数据保存失败!');
}
});
后台直接接收data参数即可:
@RequestMapping(value = "**/save.do", method = RequestMethod.POST)
public void saveBeizhu( @RequestParam(value = "data", required = false) String data,
HttpServletRequest request, HttpServletResponse response) throws Exception{
request.setCharacterEncoding("UTF-8");
log.error(data);
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
response.getWriter().print("{\"cr\":\"保存成功!\"}");
}
转载于:https://blog.51cto.com/fanson59/1406450