Ajax does not support a variety of character sets, its default character set is UTF-8, so the application of Ajax technology in the program should be timely encoding conversion, otherwise Chen Xu appears in the Chinese characters will become garbled. In general, Chinese garbled characters can be generated in the following two cases.
1. The sending path parameters contain Chinese characters and garbled characters are generated when the server accepts the parameter values.
You can submit data to the server in either the get method or the POST method. The methods for submitting data using different methods are different. When the Server accepts parameters, the methods for resolving Chinese garbled characters are different. The solution is as follows:
(1) When receiving data submitted using the get method, convert the encoding to GBK. The key code is as follows:
String Wishman = request. getparameter ("Wishman ");
Out. println ("Blessing object:" + new string (Wishman. getbytes ("ISO-8859-1"), "GBK"); // address Chinese garbled characters
(2) because the default character encoding is UTF-8 when the POST method is applied to submit data, so when receiving data submitted using the POST method, the encoding is to be converted to UTF-8, the key code is as follows:
String Wishman = request. getparameter ("Wishman ");
Out. println ("Blessing object:" + new string (Wishman. getbytes ("ISO-8859-1"), "UTF-8"); // address Chinese garbled characters
2. garbled characters are generated when the returned value of response text or responsexml contains Chinese characters.
When accepting the value of responsetext or responsexml, if it contains Chinese characters, you need to convert it to GBK or gb2312 encoding, and set the encoding format of this value page to GBK or gb2312, otherwise, garbled characters are generated.