Home >Web Front-end >JS Tutorial >Why does garbled code appear when ajax passes json?

Why does garbled code appear when ajax passes json?

php中世界最好的语言
php中世界最好的语言Original
2018-04-02 16:33:031909browse

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")

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

<spring.version>4.1.4.RELEASE</spring.version>

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!

Statement:
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