The escape (), encodeURI (), and encodeURIComponent () methods can filter out special characters that affect URL integrity. But the latter two is to convert the string to the UTF-8 to transfer, solve the problem of garbled code caused by different page encoding.
For example, if the send page is inconsistent with the Charset format of the receive page (assuming that the send page is GB2312 and the receive page is a UTF-8), use escape () the conversion and transmission of Chinese strings will cause garbled characters.
The following are various methods for URL encoding/Decoding in JS:
Escape method: the characters @ * +/A-Z 0-9 a-z are not encoded, other non-ASCII characters will be encoded with % XX encoding replacement, decoding uses unescape, the escape method cannot be used to encode the Uniform Resource Identifier (URI. Use the encodeURI and encodeURIComponent methods for encoding. EncodeURI (): Yes! @ # $ & * () = :/;? + 'A-Z 0-9 a-z, other characters will be encoded, decoding using decodeURI ();
If you want to encode more words, for example :/.., use the encodeURIComponent () method. After this method is encoded, the parameter is passed to the server as an invalid character. decodeURIComponent () is used for decoding ()
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