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

The solution to the problem of question marks and garbled characters in Chinese when passing json to the front desk using ajax

亚连
Release: 2018-05-23 09:58:01
Original
1891 people have browsed it

This article mainly introduces the solution to the problem of Chinese question marks and garbled characters when using ajax to transfer json to the front desk. Friends who need it can refer to it

I use Springmvc to transmit a json to the front desk and backend in the controller layer. There is no problem with the display. Chinese characters are displayed normally but when I reach the front desk,

Chinese characters become question marks.

Later I discovered that because @ResponseBody was used to return json in the controller, and the implementation class of @ResponseBody in the spring source code found that its default encoding was iso-8859-1, and the encoding used by the project was 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 what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Perfect solution to parsererror error under ajax cross-domain request

ajax submits mobile phone number to database verification And return the status value

AJAX SpringMVC implements the paging query function of bootstrap modal box

The above is the detailed content of The solution to the problem of question marks and garbled characters in Chinese 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!