zoukankan      html  css  js  c++  java
  • 【JS】中ajax的URL中包含中文,后台接收乱码

    【问题】
    ajax提交get请求,url中参数包含中文,后台接收到显示乱码。

    【解决方案】
    前台:

    function getSiteInfoByName(siteName){
        var res;
        $.ajax({
            url : getRootPath() + "/site/getSiteInfoByName.do?" + "siteName="
            + encodeURI(encodeURI(siteName)),
            type : "get",
            contentType : "application/json; charset=utf-8",
            dataType : "json",
            async : false,
            success : function(data) {
                res = data;
            },
            error : function(data) {
                alert("获取局点信息失败!");
                res = null;
            }
        });
        return res;
    }

    后台:

    @RequestMapping(value = "/getSiteInfoByName.do")
        @ResponseBody
        public VSiteWithBLOBs getSiteInfoByName(@RequestParam("siteName") String siteName) {    
            logger.info("Get site int by name : {}.",siteName);    
            String site_name="";
            try {
                site_name = URLDecoder.decode(siteName, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("decode chinese character failed :",e);
            }
            logger.info("Get site int by name : {}.",site_name);    
            return siteService.getSiteByName(site_name);
        }
  • 相关阅读:
    jq ajax注册检查用户名
    jq ajax页面交互
    Digit Counting UVA – 1225
    Molar mass UVA – 1586
    P1571 眼红的Medusa
    A. Digits Sequence Dividing
    Codeforces Round #535 (Div. 3) a题
    Digit Generator UVA – 1583
    Good Bye 2018 B
    电梯 HDU – 1008
  • 原文地址:https://www.cnblogs.com/tigerhsu/p/9794054.html
Copyright © 2011-2022 走看看