This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9782|Reply: 0

[JavaScript] The difference between encodeURI and encodeURIComponent methods in js

[Copy link]
Posted on 12/23/2015 5:42:44 PM | | |
1. encodeURI(), and encodeURIComponent() encode characters.

2. decodeURI(), and decodeURIComponent() decode the corresponding encoded characters.


3. The encodeURI method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks: - _ . ! ~ * ' ( ) 。

The purpose of this method is to fully encode the URI, so the encodeURI() function will not escape the following ASCII punctuation marks that have special meanings in URIs: ; /?:@&=+$, #

4. The encodeURIComponent() method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks: - _ . ! ~ * ' ( ) 。

Other characters (e.g. :; /?:@&=+$,# these punctuation marks used to separate URI components), are all replaced by one or more hexadecimal escape sequences.

5. Image explanation, the role of encodeURI on full-width Japanese and Korean Chinese characters. Instead of handling special characters in URLs, .encodeURIComponent() creates special characters in URLs and converts them into corresponding ASCII code

6. These methods are Javascrip{filtering}t functions, that is, they can only be used in Javascrip{filtering}t.

7. If you do not use decodeURI() and decodeURIComponent() on the service side, you can use fw = new String(fw.getBytes("ISO-8859-1"), "UTF-8"); Java syntax, slightly different in other languages.




Previous:c# encodeURIComponent decoding
Next:A solution to the problem of Ajax Post commits in Chinese garbled characters in IE in JQuery
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com