Ajax garbled today met the problem, at-line for a long time to find information on a variety of test methods, and finally found this article or tell me the correct way, and would like to thank. Original Address: http://www.blogjava.net/hulizhong/archive/2007/04/21/112416.html

AJAX Chinese question is divided into two broad categories:
1) Send the path of the parameters have Chinese, on the server to receive the parameter values above are garbled

For example:
var url = "a.jsp? name = Li";
xmlHTTP.open ( "post", url, true);
Solutions:
The use of javascript provided by the escape () or encodeURI () method
For example:
Client:
var url = "a.jsp? name = Li";
url = encodeURI (url);
url = encodeURI (url); / / twice, it is the key to [specify why, I do not know]
/********************************************/
It was also written in var url = "a.jsp? Name = escape (" Li ")";
Functions and similar encodeURI Ways.
/********************************************/
xmlHTTP.setrequestheader ( "cache-control", "no-cache");
xmlHTTP.setrequestheader ( "Content-Type", "application / x-www-form-urlencoded");
xmlHTTP.setrequestheader ( "contentType", "text / html; charset = uft-8") / / specify the encoding format to send data
xmlHTTP.open ( "post", url, true);
Server-side:
String name = request.getParameter ( "name");
name = java.net.URLDecoder.decode ( "name", "UTF-8");

2) Return to the responseText value or responseXML contains Chinese are garbled
Reasons: AJAX in the receiving responseText or when the value of responseXML are in accordance with the UTF-8 format decoding, if the server send the data above is not UTF-8 format, then receive the value of responseText or responseXML may have garbled.
The solution: send data at the server specified format:
In the jsp file:
response.setContentType ( "text / text; charset = UTF-8 ");// the back are txt text file
Or
response.setContentType ( "text / xml; charset = UTF-8 ");// return the xml document

Aggregate: 1) ajax submit data format defaults to utf-8, the use of javascript provided by the escape () or encodeURI () method. At a time when the receiving server-side to use java.net.URLDecoder.decode (""," UTF -8 ") method to decode.
2) xtmlhttp return the data the default character encoding is utf-8, so the server to the client when sending data, but also the use of utf-8 encoding
If the above method still can not solve the garbage problem, you try put jsp, htm, java file using UTF-8 encoding format.
In short: Units of data before and after the interactive use utf-8 encoding on the list.

-----------------------------------------------
js to encode characters involved in three functions: escape, encodeURI, encodeURIComponent, the corresponding three decoding function: unescape, decodeURI, decodeURIComponent

1, transmission parameters need to use encodeURIComponent, this portfolio would not be # url special characters, such as cut-off.

For example: <script language="javascript"> document.write ( '<a href = "http://passport.baidu.com/?logout&aid=7&u =' + encodeURIComponent (" http://cang.baidu.com/ bruce42 ")+'"> Exit </ a >');</ script>

2, Jump to url when the overall use of encodeURI

For example: Location.href = encodeURI ( "http://cang.baidu.com/do/s?word = Baidu & ct = 21");

3, js the use of data can use the escape

[Huoho.Com Edit]
For example: the record collection in history.

4, escape to the outside of unicode values 0-255 encode output% u **** format, other cases escape, encodeURI, encodeURIComponent encoding the same result.

Most frequently used for encodeURIComponent, it will be Chinese, Korean and other special characters into utf-8 format url encoding, so if the transmission parameters give the background necessary to use encodeURIComponent Backgrounds decoding when necessary to utf-8 support (form of coding coding methods and the same manner as the current page)

escape characters do not have 69 coding :*,+,-,.,/,@,_, 0-9, az, AZ

Character encoding encodeURI not have 82 :!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~, 0 -- 9, az, AZ

encodeURIComponent encoding characters do not have 71:!,',(,),*,-,.,_,~, 0-9, az, AZ