Chinese javascript AJAX Problem summary
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
Related Posts of Chinese javascript AJAX Problem summary
-
Based on Spring's Hibernate Search full-text search function of sample
Database: Oracle 9i JDBC Driver: OJDBC14 Development Environment: Eclipse-JEE Spring version: Spring 2.0.6 Hibernate version: Hibernate Core 3.2.5/Hibernate Annotation 3.3.0/Hibernate Validator 3.0.0/Hibernate Search 3.0.0 Beta4 / / jdbc.properties (JDBC
-
Some interview questions java
The first is the company give you a chance to meet, it is necessary to know to meet from time to equal the interview, and have a lot of companies to see you at the first time will give you a ready point of doing something trivial, these questions, al ...
-
Spring + Hibernate to use Glassfish Database Connection Pool
applicationContext.xml file content <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = " http://www.springframework.org/schema/beans " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " ...
-
Application of spring struts2.0 hibernate HQL
Therefore, in the development of statistical inquiry system, as far as possible through the use of select statement to write the required query property way back relational data, and avoid using the first query return persistent object (in this way a ...
-
Process migration from tomcat to websphere changes
Process migration from tomcat to websphere changes Because customers use the web application server software used by different what tomcat5, tomcat6, websphere5.1, websphere6.1, weblogic8, and so on, and the software used inconsistent standards, ibm& ...
-
Ruby on Rails Routing - Simple Examples
This article contains a list of ruby on rails routing examples. If you find you have any questions please leave a comment. Routes are processed from the top of routes.rb down. If a route is matched it will stop processing the routes.rb file and use t ...
-
JAVA EE JSP_JNDI
dsfdsa http://lindows.javaeye.com/admin/blogs/213348 Tomcat 6 with the connection pool data source configuration http://www.blogjava.net/ec2008/archive/2008/07/19/216063.html project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...
-
Servlet brief introduction
Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...
-
Spring2.0 + hibernate3.1 + log4j + mysql demo
applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com
-
The level Hibernate cache
Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...













Leave a Reply