Today's project encountered a garbled problem, from JS to the URL to the server, the URL has Chinese parameters, the server read the Chinese parameters are all "? ", check the online JS coding related data to solve.
Here's how to fix it:
1, in JS in the Chinese parameter two times transcoding
var login_name = document.getElementById ("loginname"=
2. Decoding the parameters on the server side
= paramutil.getstring (Request, "login_name")
When using a URL for parameter passing, some Chinese name arguments or URL addresses are often passed, and conversion errors occur during background processing. In some pass-through pages use GB2312, and the Receive page uses UTF8, so that the received parameters may be inconsistent with the original. URLs that are encoded using the server-side UrlEncode function are not the same as the URLs encoded with the encodeURI function of client JavaScript.
coding methods in javascript:
Escape () method:
Encodes the specified string using the ISO Latin character set. All space characters, punctuation marks, special characters, and other non-ASCII characters are converted to the character encoding in the%xx format (XX equals the encoded 16-digit number of the character in the character set table). For example, the encoding for a space character is%20. The Unescape method is the opposite. Characters that are not encoded by this method: @ */+
encodeURI () Method:
Converts the URI string into an escape format using the UTF-8 encoding format. Characters that will not be encoded by this method:! @ # $& * () =:/;? +
encodeURIComponent () Method:
Converts the URI string into an escape format using the UTF-8 encoding format. Compared to encodeURI (), this method encodes more characters, such as characters. So if the string contains several parts of the URI, it cannot be encoded in this way, otherwise the URL will display an error after the/character is encoded. Characters that will not be encoded by this method:! * ( )
Therefore, for the Chinese string, if you do not want to convert the string encoding format into UTF-8 format (such as the original page and the target page charset is consistent), only need to use escape. If your page is GB2312 or other encoding, and the page that accepts the parameter is UTF-8 encoded, it is necessary to use encodeURI or encodeuricomponent.
In addition, Encodeuri/encodeuricomponent was introduced after javascript1.5, and escape is available in the javascript1.0 version.
The garbled problem caused by the Chinese parameter of JS URL