Recently, some friends reported that Chinese garbled characters appeared when using jquery.ajax to return json. It is very difficult to encounter this problem. Let me help you solve the problem of Chinese garbled characters when JQuery ajax returns json. Interested friends can follow along to learn more. Bar
Using jQuery ajax call to return json, Chinese garbled problem
Js code is as follows:
$.ajax({ url: '/test/testAction.do?method=test', type: 'POST', dataType: 'json', timeout: 5000, async: false, error: function(){ alert('获取数据失败!'); }, success: function(json){ jsObject = eval(json); } }); return jsObject;
Js code
<span style="font-size: x-small;">$.ajax({ url: '/test/testAction.do?method=test', type: 'POST', dataType: 'json', timeout: 5000, async: false, error: function(){ alert('获取数据失败!'); }, success: function(json){ jsObject = eval(json); } }); return jsObject;</span> action:
Java code
JSONArray json = JSONArray.fromObject(SysList);//SysList是一个List // 设置response的ContentType解决中文乱码 response.setContentType("text/html;charset=UTF-8"); response.getWriter().print(json.toString()); return null; Java代码 <span style="font-size: x-small;">JSONArray json = JSONArray.fromObject(SysList);//SysList是一个List // 设置response的ContentType解决中文乱码 response.setContentType("text/html;charset=UTF-8"); response.getWriter().print(json.toString()); return null;</span>
The above is I compiled it for everyone, I hope it will be helpful to everyone in the future.
Related articles:
How to use the ajax post method in the Django framework
Using jquery ajax in django post data appears 403 Error solution
Detailed explanation of ajax jtemplate to implement dynamic paging
The above is the detailed content of How to solve the problem of Chinese garbled characters when JQuery ajax returns json. For more information, please follow other related articles on the PHP Chinese website!