Home  >  Article  >  Web Front-end  >  Simple example processing url special symbols & processing (2 methods)_javascript skills

Simple example processing url special symbols & processing (2 methods)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:38:291232browse

The problem I encountered is: the parameter content in the url contains & matches. I have two ways to solve it
. One method is: use JS to transcode on the page. The example is as follows (front-end processing)

Copy code The code is as follows:

${group.cn })

2. You can use encodeURI as a whole when making URL jumps. For 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: history record in collection.
4. When escape encodes unicode values ​​other than 0-255, it outputs the %u**** format. In other cases, the encoding results of escape, encodeURI, and encodeURIComponent are the same.

The most commonly used should be encodeURIComponent, which converts Chinese, Korean and other special characters into url encoding in utf-8 format, so if you need to use encodeURIComponent to pass parameters to the background, you need background decoding to support utf-8 (The encoding method in the form is the same as the encoding method of the current page)

There are 69 characters that are not encoded by escape: *, , -, ., /, @, _, 0-9, a-z, A-Z
There are 82 characters that encodeURI does not encode: !, #, $, &, ', (, ), *, , , , - , . , / , : , ; , = , ? , @ , _ , ~ , 0-9 , a-z , A-Z
encodeURIComponent has 71 unencoded characters: !, ' , ( , ) , * , - , . , _ , ~ , 0-9 , a-z , A-Z

The following is in the url Possible special characters and encoded values ​​in the URL: (omitted)
It was found in the project that the encodeURI() encoding conversion is performed directly on the parameter part of the URL, and when the background servlet obtains it through getParamater(), The correct value can be obtained directly without conversion. Note: The parameters are not used in Chinese, and the framework uses the struts framework.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn