How to deal with the Chinese garbled json returned by jquery+ajax

php中世界最好的语言
Release: 2018-04-26 14:53:01
Original
2595 people have browsed it

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;
Copy after login

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:
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!