zoukankan      html  css  js  c++  java
  • jquery ajax 传数据到后台乱码的处理方法

    前台页面先对中文进行编码,如下红色字体:

    function saveCommentTemplate()
    {
        $.ajax({
            cache : false,
            type:'get',
            dataType:'json',
                url:'comment/insert',
                contentType:'application/json;charset=UTF-8',  
                data:{name:encodeURI($("#name").val()),
                    content:encodeURI($("#content").val())},
            success:function(data){
                alert("ok") 
            },
            error: function() {  
                alert("error")  
            }  
        });
        $("#bottom").hide();
    }

    后台代码,在对数据进行解码:

    @RequestMapping(value = "insert")
        @ResponseBody
        public void insert(@RequestParam("name") String name,@RequestParam("content")String content) throws UnsupportedEncodingException
        {
            name=URLDecoder.decode(name,"UTF-8");
            content=URLDecoder.decode(content,"UTF-8");
            commentTemplateService.saveCommentTemplate(name,content);
        }
  • 相关阅读:
    hdu 1258 DFS
    hdu2488 dfs
    poj1915 BFS
    hdu1372 BFS求最短路径长度
    poj3264 线段树
    hdu 2438Turn the corner 三分
    hdu3714 三分
    【转载】单点登陆
    ajax从入门到深入精通
    Web前端技术体系大全搜索
  • 原文地址:https://www.cnblogs.com/dscs/p/5740425.html
Copyright © 2011-2022 走看看