Home  >  Article  >  Backend Development  >  How to solve the problem of garbled question marks when passing json to the front desk using ajax?

How to solve the problem of garbled question marks when passing json to the front desk using ajax?

小云云
小云云Original
2018-01-08 13:28:452016browse

The Springmvc used transmits a json to the front desk in the controller layer. The background display is no problem, and Chinese is displayed normally and reaches the front desk. This article mainly introduces the solution to the problem of question marks and garbled characters in Chinese when using ajax to transfer json to the front desk. Friends in need can refer to it. I hope it can help everyone.

The Chinese becomes a question mark.

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>

The above is the solution introduced by the editor to the problem of garbled question marks in Chinese when passing json to the front desk using ajax. I hope it will be helpful to everyone.

Related recommendations:

How to transfer json objects between html?

PHP transfers Json data between different pages Sample Code_PHP Tutorial

JSON Advanced Part 2: Passing JSON Data in AJAX Way_PHP Tutorial

The above is the detailed content of How to solve the problem of garbled question marks when passing json to the front desk using ajax?. 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