This article mainly introduces how to obtain Chinese garbled characters in return values asynchronously by JQuery. In addition to the normal encoding settings, you must set a setCharacterEncoding parameter to avoid garbled characters, if you want to obtain the List Value asynchronously using jqgrid, you can refer to the following: in case of a problem, the data obtained from the database on the server does not contain Chinese garbled characters (logs are not garbled ), however, garbled characters occur during asynchronous transmission to the customer. The server has been coded (UTF-8 encoding ). I started to suspect that it was a client problem. For example, the client and server encoding were inconsistent. I also suspected that the jqGrid tool function was missing the contentType: "application/x-www-form-urlencoded; charset = UTF-8 ", and so on.
None of the results. After several hours, I found that the original code was still on the server side and neglected.
@ RequestMapping (value = "/searchUserList. form ") @ ResponseBody public void searchUserList (int page, int rows, HttpServletRequest request, HttpServletResponse response) throws IOException {System. out. println ("idcard =" + idCard + "\ n page =" + page + "\ n rows =" + rows); List
List = userService. findByIDCard (idCard); int totalRecord = list. size (); int totalPage = totalRecord % rows = 0? TotalRecord/rows: (totalRecord/rows + 1); int index = (page-1) * rows; int pageSize = rows; String json = "{\" total \": \ "" + totalPage + "\", \ "page \": \ "" + page + "\", \ "records \": \ "" + totalRecord + "\", \ "rows \": ["; for (int I = index; I <pageSize + index & I