jquery1.4.2 ajax 中文亂碼問題解決方案

前端ajax用POST方式:
 $.ajax({
                type : "POST",
                url : "**/save.do",
                async : true,
                dataType : "json",
                data : "data=中文",
                success : function(resp) {
                    alert(resp.cr); //必須嚴格按照JSON的標準來
                },
                error : function() {
                    alert('數據保存失敗!');
                }
            });
後臺直接接收data參數便可:      
@RequestMapping(value = "**/save.do", method = RequestMethod.POST)
    public void saveBeizhu( @RequestParam(value = "data", required = false) String data,
            HttpServletRequest request, HttpServletResponse response) throws Exception{
        request.setCharacterEncoding("UTF-8");
        log.error(data);
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().print("{\"cr\":\"保存成功!\"}");
    }
相關文章
相關標籤/搜索