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 '))}