控制台报如下消息提示:
Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]
2019-09-11 22:48:32.829 WARN 12904 --- [nio-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]
2019-09-11 22:49:26.551 WARN 12904 --- [nio-8080-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]
说明控制器已经接收到了请求,jquery没有设置
contentType或直接设置为application/x-www-form-urlencoded;charset=UTF-8
因为传递的json格式的对象,应设置为 contentType: 'application/json;charset=UTF-8'
$.ajax({
url: "login",
type: "POST",
data: data,
dataType: "json",
async: false,
contentType:'application/x-www-form-urlencoded;charset=UTF-8',//设置前
contentType:'application/json;charset=UTF-8', //设置后
success: function (result) {
var newData = JSON.stringify(result); //将json对象转换为字符串
newData = eval("(" + newData + ")"); //解析json
var msg = newData.msg;
alert(msg);
},
error: function () {
alert("提交请求失败!");
}
});
更多推荐
报错: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not
发布评论