The escape method does not encode character +. We know that in the form field submitted by the user, if there is a space, it will be converted to a + character, and the server will think that the + number represents a space during parsing. Due to this defect, the escape method cannot correctly process all non-ASCII characters. Instead, you should try to avoid using the escape method. Instead, you 'd better choose the encodeURIComponent () method.
Unencoded characters of escape (): @ */+
Compared with the escape method, the encodeURI method is more professional. When you need to encode an entire URI, you can use this method, because the valid characters in the URI are not encoded and converted. It should be noted that the character 'is also a valid character in the URI, so it will not be converted by encoding.
EncodeURI () unencoded characters :~! @ # $ & * () = :/,;? +'
The encodeURIComponent method is the most commonly used method for encoding a single URIComponent (request parameter. It should be noted that the character 'is also a valid character in the URI, so it will not be converted by encoding.
EncodeURIComponent () unencoded characters :~! *()'
JavaScript code involves three functions: escape, encodeURI, and encodeURIComponent. The corresponding three decoding functions are: unescape, decodeURI, and decodeURIComponent.
1. encodeURIComponent is required when passing parameters so that the combined url will not be truncated by special characters such.
Example: <script language = "javascript"> document. write ('<a href = "http://passport.baidu.com /? Logout & aid = 7 & u = + encodeURIComponent ("http://cang.baidu.com/bruce42") + "> exit </a> '); </script>
2. encodeURI can be used for url redirection.
Example: location. href = encodeuri ("http://cang.baidu.com/do/s? WORD = Baidu & Ct = 21 ");
3. You can use escape when JS uses data.
For example, search for the history record in the bucket.
4. When encoding Unicode values other than 0-, escape outputs % u *** format. In other cases, escape, encodeuri, and encodeuricomponent have the same encoding result.
The most commonly used format is encodeuricomponent, which converts special characters such as Chinese and Korean into UTF-8 URL encoding, therefore, if you want to use encodeuricomponent to transmit parameters to the backend, you must use backend decoding to support UTF-8 (the encoding method in form is the same as that on the current page)
Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, A-Z, A-Z
Encodeuri is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, A-Z, A-Z
Encodeuricomponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, A-Z, A-Z