Troubleshooting Chinese Character Display with Ajax

  • Thread starter Thread starter ngkamsengpeter
  • Start date Start date
  • Tags Tags
    Troubleshooting
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
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 ?
 
Physics 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.