Because of the need for a new system, we have re-studied JS scripts. During the new URL encoding, we found that the webpage encoding format has a great impact on JS. Here we will write a little bit.
{Var B = siteUrl + this. actionUrl + (this. type = "all "? "": This. type) + "& SearchWord =" + encodeURIComponent (A). replace (/'/g, "% 27"); $ redirect (B )}}
At the time of production, it is found that the outgoing data packet encoding is all in the UTF-8 format, and after correcting the webpage encoding is also not reflected, finally, the problem can be solved after the ENCODE is modified to DECODE.
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.
For example:
2. encodeURI can be used for url redirection.
Example: Location. href = "/encodeURI" ("http://www.jb51.net/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