How to solve the problem of question mark garbled characters when json is transmitted to the front-end using ajax? ajaxjson

Source: Internet
Author: User

How to solve the problem of question mark garbled characters when json is transmitted to the front-end using ajax? ajaxjson

Springmvc I use transmits a json file to the front-end at the controller layer. It is okay to display the text in the background. The Chinese text is displayed normally and then to the front-end.

The Chinese character becomes a question mark.

Later found, because the controller returned json with @ ResponseBody, and spring source code in the implementation class @ ResponseBody found that the default encoding is iso-8859-1, and the project is encoded as UTF-8, therefore, garbled characters may occur when the Chinese characters are passed.

Here I use annotations to solve the problem:

@ RequestMapping (value = "/echarts. do", produces = "application/json; charset = UTF-8 ")

This method is applicable to the new spring version. The version of this project:

<Spring. version> 4.1.4.RELEASE </spring. version>

The above is a small series of solutions to the problem of question mark garbled characters when using ajax to transmit json to the front-end Chinese. I hope it will help you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.