Home > Web Front-end > JS Tutorial > url encoding js url parameter transmission Chinese garbled solution_javascript skills

url encoding js url parameter transmission Chinese garbled solution_javascript skills

WBOY
Release: 2016-05-16 18:29:43
Original
1280 people have browsed it
1. In the configuration file web.config, add the encoding method of the entire website in the section.

In this way, the parameters are transmitted in the Chinese encoding method of gb2312. The general default is utf-8.
2. When passing parameters, they are encoded first before transmission, and when receiving, they are encoded first and then received.
string mm=Server.URLEncode(you);
Response.Redirect(index.aspx?mm= mm);
Then decode on the receiving page:
string mm = Server.URLDecode (Requext.querystring(mm));
There are several methods to encode URL strings in JavaScript: escape(), encodeURI(), and encodeURIComponent(). These encodings play different roles.
escape() method:
Encode the specified string using the ISO Latin character set. All spaces, punctuation marks, special characters and other non-ASCII characters will be converted into character encoding in %xx format (xx is equal to the hexadecimal number of the character's encoding in the character set table). For example, the encoding corresponding to the space character is .
Characters that will not be encoded by this method: @ * /
encodeURI() method:
Convert the URI string into an escape format string using UTF-8 encoding format.
Characters that will not be encoded by this method: ! @ # $& * ( ) = : / ; ? '
encodeURIComponent() method:
Convert the URI string into escape using UTF-8 encoding format Format string. Compared with encodeURI(), this method will encode more characters, such as / and other characters. So if the string contains several parts of the URI, you cannot use this method to encode, otherwise the URL will display an error after the / character is encoded.
Characters that will not be encoded by this method: ! * ( ) '
Therefore, for Chinese strings, if you do not want to convert the string encoding format into UTF-8 format (such as the original page and target When the charset of the page is consistent), you only need to use escape. If your page is GB2312 or other encoding, and the page that accepts parameters is UTF-8 encoded, you must use encodeURI or encodeURIComponent.
In addition, encodeURI/encodeURIComponent was introduced after javascript1.5, and escape was available in javascript1.0.

Pass parameter: use encodeURI("url parameter") to encode the url
Receive parameter: use decodeURI("received value") to decode
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template