before the data is passed, encode the Chinese in the following red font:
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 ();
when the data is sent over, the data is decoded:
@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); }
The processing method of jquery Ajax transmitting data to the background garbled