• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Chinese javascript AJAX Problem summary ...

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

 Original Source:
http://www.codeweblog.com/chinese-javascript-ajax-problem-summary/

AddThis Social Bookmark Button

Posted at 11:00:14 am | Permalink | Posted in Javascript  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

MessengerFX

e-messenger

ILoveIM

Top 20 Ruby CMS

eBuddy

MSN Web Messenger



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (162)
  • Ajax (82)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (20)
  • Chat (45)
  • ColdFusion (3)
  • CSS (75)
  • Email (23)
  • Facebook (83)
  • Flash (19)
  • Google (54)
  • Html (27)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (54)
  • Javascript (265)
  • jQuery (159)
  • JSON (61)
  • Perl (2)
  • PHP (156)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (29)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (217)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (28)
  • YUI (12)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange