Differences between js character encoding Functions

Source: Internet
Author: User

1. escape encodes characters other than ansi 0-and outputs the unicode value in % u *** format. The escape method returns a string value (in Unicode format) containing charstring content ). All spaces, punctuation marks, accents, and other non-ASCII characters are replaced by % xx encoding. xx equals to the hexadecimal number of the character. For example, "% 20" is returned by a space"
Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, a-z, A-Z

2. encodeURI is similar to escape and used for address bar encoding.
EncodeURI is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, a-z, A-Z

3. encodeURIComponent is used for address bar encoding. Encodes a text string into a valid component of a uniform resource identifier (URI. It converts special characters such as Chinese and Korean into UTF-8 url encoding. If your page encoding is gb2312, the server will receive garbled characters.
EncodeURIComponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, a-z, A-Z

Therefore, js can use escape when using data. For address bar data, it is best to use encodeURIComponent for encoding.

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.