vue.js ajax传参 后台参数不为application/x-www-form-urlencoded MIME

post请求 过滤器 encodeURI未解决!! 使用contentType也于事无补

help:
https://blog.csdn.net/justlov...

测试环境1:ajax带参请求:name
google
get/post 无变化
前台:直接传递name(值可获取)
后台:解码/不解 效果一致
当参数nam值通过浏览器ajax request请求到后台不为
application/x-www-form-urlencoded MIME 值

效果与编码一致

浏览器的request请求值为application/x-www-form-urlencoded MIME
request 200

个人考虑:前台与后台编码不一致

前端:

data() {
    var name=this.$route.query.name;
        $.ajax({
            url : 'topInfo?name='+name,
            contentType: "application/json; charset=utf-8",
            type : 'POST', //GET
            async : false, //或false,是否异步
            //timeout : 5000, //超时时间
            dataType : 'json', //返回的数据格式:
            success : function(data) {
                this.items = data.data;
            },
            error : function(data) {
                alert("失败!!");
            }
        })
        debugger;
    return {
        items
    }
},

后台:

public void moreList() throws Exception
{
    if("".equals(name)||name==null){
        SessionUtils.outRightJSon(this.response,"--null--");
    } else if(name.equals("%E5%91%A8%E8%80%81%E5%B8%88")){
        SessionUtils.outRightJSon(this.response,"--周老师--");
    }
    //URLDecoder.decode(name,"UTF-8")
    request.setCharacterEncoding("utf-8");
    ContentVO listContentVo = topServiceImpl.more(name,5);
    SessionUtils.outRightJSon(this.response, listContentVo);
}
阅读 3k
1 个回答

这明显前端url编码了,后端解码就是了。

但可能前后端编码与解码的规则不统一,如果没有什么特殊字符,不要编码也可以。

另外,不是说 post请求吗?怎么截图里不是。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题