Home > Article > Web Front-end > Why does garbled code appear when ajax passes json?
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!