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

小云云
Release: 2023-03-19 11:38:02
Original
2004 people have browsed it

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

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!

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!