Home > Web Front-end > JS Tutorial > body text

Why does garbled code appear when ajax passes json?

php中世界最好的语言
Release: 2018-04-02 16:33:03
Original
1881 people have browsed it

This time I will bring you why garbled characters appear when ajax transmits json, and how to solve the problem of garbled characters when ajax transmits json. take a look. I use Spring

mvc

. I transmit a json to the front desk in the controller layer. The background display is fine. Chinese characters are displayed normally but when I reach the front desk, Chinese characters become question marks. .

Later I discovered that because @ResponseBody is used to return json in the controller, and the implementation class of @ResponseBody in the spring source code found that its default encoding is iso-8859-1, and the encoding used by the project is utf-8 , so there will be garbled characters when transmitting Chinese.

Here I used annotations to solve the problem:

@RequestMapping(value="/echarts.do", produces = "application/json; charset=utf-8")
Copy after login

This method is more suitable for the new version of spring. The version of this project:

<spring.version>4.1.4.RELEASE</spring.version>
Copy after login

I believe you have read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How does ajax implement the paging query function of bootstrap modal box

##Ajax drop-down list to add data

The above is the detailed content of Why does garbled code appear when ajax passes json?. 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 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!