This article describes how to use the escape Function to solve Chinese garbled characters transmitted by ajax in Javascript. It is a very practical technique, for more information about how to use the escape Function to solve Chinese garbled characters transmitted by ajax in Javascript, see the example below. The specific method is as follows:
I. Problem description:
Originally in the Web Effect of escape () is the Chinese according to the iso-8859-1 Character Set url encoding, that through request. getparameter () can directly obtain the request parameters, but later javascript will replace escape () with the unicode Character Set encoding, so that, in the jsp tutorial and servlet, the request parameters cannot be obtained directly. I do not know the specific reason.
Ii. solution:
1. encode the Chinese characters twice. If you want to pass the parameter name and the value is "hello", the url format is .... name = escape ("hello. getparameter () can get the encoded parameter.
2. Because the obtained parameter is in the format of % 25u4f60% 25u597d, the standard urldecoder cannot be used. decode () to decode. Fortunately, there are enough coders in the world. I have found a tool class on the Internet to implement escape () and unescape () encoding and decoding in javascript.
The Code is as follows: