This time I will show you how to deal with jquery ajax returning json Chinese garbled characters, and what are theprecautionswhen dealing with jquery ajax returning json Chinese garbled characters. The following is a practical case, let's take a look.
Using jQuery ajax call to return json, ChineseGarbled code 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
$.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; 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代码 JSONArray json = JSONArray.fromObject(SysList);//SysList是一个List // 设置response的ContentType解决中文乱码 response.setContentType("text/html;charset=UTF-8"); response.getWriter().print(json.toString()); return null;
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
JSONP solves ajax cross-domain problems (with code)
What are the implementations of AJAX secondary linkage method
The above is the detailed content of How to deal with the Chinese garbled json returned by jquery+ajax. For more information, please follow other related articles on the PHP Chinese website!