Home  >  Article  >  Web Front-end  >  The solution to the problem of question marks and garbled characters in Chinese when passing json to the front desk using ajax

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

亚连
亚连Original
2018-05-23 09:58:011923browse

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

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 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!

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