To: AJAX Chinese lessons
Related Tags:
Recently wrote a ajax, testing has been no problem, the results into other computers, which have three to five computer Display garbled, the enquiries about, there is a conclusion, very good! Ajax return to the original values are utf-8 decoder ,
AJAX Chinese issues fall into two broad categories:
1) Send in the path of Chinese parameters in the server parameter values of the receiver is garbled
For example:
Var url = "a.jsp? Name = Li";
XmlHTTP.open ( "post", url, true);
The solution:
Javascript provided by the use of the escape () or encodeURI () method
For example:
Client:
Var url = "a.jsp? Name = Li";
Url = encodeURI (url);
Url = encodeURI (url); / / twice, it is key to [specify why, I do not know]
/********************************************/
It was also written var url = "a.jsp? Name = escape (" Li ")";
EncodeURI similar functions and methods.
/********************************************/
XmlHTTP.setrequestheader ( "cache-control", "no-cache");
XmlHTTP.setrequestheader ( "Content-Type", "application / x-www-form-urlencoded");
XmlHTTP.setrequestheader ( "contentType", "text / html; charset = uft-8") / / designated sent the data coding format
XmlHTTP.open ( "post", url, true);
Server:
String name = request.getParameter ( "name");
Name = java.net.URLDecoder.decode ( "name", "UTF-8");
2) to return the responseText responseXML or the value of the presence of Chinese is garbled
Cause: AJAX in the receiving responseText responseXML or the value of time in accordance with the UTF-8 format decoding, if the server of the data is not sent UTF-8 format, or to receive responseText responseXML value is likely to hash.
The solution: send data in the server specified format:
In jsp file:
Response.setContentType ( "text / text; charset = UTF-8 ");// txt is the return of text files
Or
Response.setContentType ( "text / xml; charset = UTF-8 ");// return to the xml
Aggregate: 1) ajax the default data format for utf-8, the use of javascript provide escape () or encodeURI () method. Reception in the server when to use UTF java.net.URLDecoder.decode (""," -8 ") method for decoding.
2) xtmlhttp return of the default character encoding data is utf-8, so the client to the server when sending data, but also use utf-8 encoding
If the hash is still unresolved problems, then you try to jsp, htm, java document with UTF-8 encoding format.
In short: after-use interactive data utf-8 encoded on the trip.
3) If asp beginning to show normal refresh hash, and the following statements
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936"%>
<meta Http-equiv="Content-Type" content="text/html;charset=gb2312">
<%
Response.Charset = "GB2312"
Session.CodePage = 936%>
- CSS Manual (4) Border Border
- CSS intensive manual (4)
- Css Manual (c) Font font
- CSS intensive manual (2)
- CSS intensive manual (7)
- CSS Development Manual [Author: nilxin]
- CSS quick Manual 1
- CSS intensive manual (3)
- Css Manual (6) List List
- CSS development manual
- CSS intensive manual 4
- Chinese typesetting experience CSS
- CSS quick Manual 3
- Css Manual (7) Classification Classification
- Css Manual (1) Background Background
- All commonly used language reference manual for manual HTML | CSS manuals | JScript Manual | VbScript Manual | ASP Manual | PHP Manual | SQL manual | Site effects | ADO Manual
- Css intensive manual (1)
- CSS intensive manual (5)
- Css Manual (2) [Text
- CSS intensive manual 2




