In general, the parameters in the URL should use the URL encoding rules, that is, the parameter string in addition to-_. All non-alphanumeric characters are replaced with a percent sign (%) followed by a two-bit hexadecimal number, and the space is encoded as a plus (+).
But for parameters with Chinese, this encoding makes the encoded string very long.
If you want to encode a parameter in a shorter way, you can encode the string in base64 encoding, but Base64 encoding cannot handle the Chinese in JavaScript, because the Chinese in JavaScript are saved in UTF-16 mode.
Base64 can only handle single-byte characters, so it is not possible to encode a JavaScript string with Chinese directly using Base64.
However, it is possible to convert UTF-16 encoded Chinese into UTF-8 by utf.js the Utf16to8 provided in this program and then base64 code.
This encoded string, after being passed to the server side, can be decoded directly through Base64_decode into a UTF-8 Chinese string.
But there is one more question to be aware of.
The plus sign (+) is used in the Base64 encoding, and the + is treated as a space when the URL is passed, so it is necessary to replace the plus sign in the Base64 encoded string with%2B to be passed as a URL parameter.
Otherwise, there will be an error after the server-side decoding.
So what we need to do is encodeURI (str). replace (/\+/g, '%2b ')
The above is a small series for everyone to talk about in JS transfer parameters including the plus (+) way of handling all the content, I hope that we support cloud Habitat Community ~