A Chinese garbled solution (percent error) occurs when ajax/fetch uploads rich texts ),

Source: Internet
Author: User

A Chinese garbled solution (percent error) occurs when ajax/fetch uploads rich texts ),

Recently, I am writing my own project. I encountered the problem of garbled Chinese characters in the rich text parameters received by the nodejs background.

At first, I thought it was a character encoding error, so I set UTF-8 in the request parameter, that is:

Headers :{

'Content-type': 'x-www-form-urlencoded; charset = UTF-8'

}

This can indeed solve this problem, but my problem is still not solved, so later I carefully found that my uploaded text contains a percent sign %, the root cause of the problem is found. encodeURIComponent ("Chinese") will have a percent sign, so we can know that fetch will automatically encode the data when processing the uploaded data, so on the frontend side, you can perform secondary encoding on the uploaded data and encode '%' into '% 25'. Then, the data can be correctly obtained at the backend:

Data: {id: 1, content: encodeURI ('item '))}

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.