Troubleshooting Chinese Character Display with Ajax

  • Thread starter Thread starter ngkamsengpeter
  • Start date Start date
  • Tags Tags
    Troubleshooting
Click For Summary
SUMMARY

The discussion focuses on troubleshooting the display of Chinese characters when using Ajax to gather information from a webpage. Users encounter issues where characters appear as ������� instead of the correct Chinese characters. The problem arises because JavaScript interprets the response as ASCII unless the characters are properly escaped. To resolve this, developers should ensure that Unicode characters are escaped using the format \u####, or consider using an IFrame as an alternative method for displaying content.

PREREQUISITES
  • Understanding of Ajax and how it retrieves data from servers
  • Knowledge of JavaScript string handling and character encoding
  • Familiarity with Unicode character representation
  • Basic experience with HTML and DOM manipulation
NEXT STEPS
  • Learn how to properly escape Unicode characters in JavaScript
  • Research the use of IFrames for content display in web applications
  • Explore server-side encoding settings to ensure proper character transmission
  • Investigate the use of XMLHttpRequest and Fetch API for handling character encoding
USEFUL FOR

Web developers, front-end engineers, and anyone working with internationalization and character encoding in web applications.

ngkamsengpeter
Messages
193
Reaction score
0
When I using ajax to gather information from a webpage , it show ������� for the chinese character , but when i run the webpage separately it can show the right character.
I use responseText to gather information and use innerHTML to show on the webpage.What is the problem ?Do i need to set the encoding using javascript , but how ?
 
Technology news on Phys.org
That's probably because when javascript receives the text string returned from the server it interprets it as ASCII. As far as i know Javascript will only interpret a character string as Unicode if the characters are appropriately escaped. For example, unicode characters in Javascript use the following escape sequence:
\u####
Where #### is a valid hexadecimal digit, such as :
Code:
<script>
alert("This is a unicode character: \u8880");
</script>

You might need to escape each character appropriately at the server if you want to use Ajax. Maybe you can use an IFrame instead.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 16 ·
Replies
16
Views
6K
Replies
1
Views
8K