报错: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]

编程知识 更新时间:2023-04-05 07:11:36

 控制台报如下消息提示:

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

本文发布于:2023-04-05 07:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/7ff119690838283ec697c105f861aec3.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   type   application   www   Content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 45470文章数
  • 14阅读数
  • 0评论数