• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax foriegn word issue

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a small ajax in my page that when user entered an English word it populates the other input text field with different language translation.
An example Ajax response is:
GOOD!!BUENA!!BONNE!!好!!
If you paste the above line in a html file, it will show the correct translated words. But when I use javascript to retrieve the words and set the value for the input text field, the fourth word is always show 好 , not the actually word I would like user to see.
How should I fix it?

Thanks

Davidd
[ December 10, 2008: Message edited by: Davidd Smith ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the response setting the correct character set coming back?

Eric
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think so. Actually the response is like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>

</head>

<body>

GOOD!!BUENA!!BONNE!!好!!!

</body>

</html>
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the http headers, do you see the correct encoding? If you open the file directly, does it render right?

Eric
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes. The header show correct encoding and if I open the file directly it shows correctly. Only when I use javascript to set a value of input text field, that field does not show correctly.

Thanks
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually The above posts are all show correct word 好 . They were parsed by the browser. What I put in the original text is &-#-2-2-9-0-9-; , please stripe the '-' , otherwise it will still show the correct word.

I guess when javascript put the code in the inputtext field, the browser does not parse it, just like the raw code entered by user. Anyone has any idea to convert the code to after parsing word in Javascript?

Thanks

Jeff
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if the solution here works: http://bytes.com/groups/javascript/458419-how-can-i-convert-some-html-entities-character

Eric
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What a magic! It works. Thank you Eric.


Jeff
[ December 11, 2008: Message edited by: Davidd Smith ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fromCharCode returns a string created by using the specified Unicode value.

If you scroll down to the bottom of the page here: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/String/Replace You can see how string.replace allows the function as the second parameter and what the arguments are.

and the " A || B " is saying use A if it has a value and if A does not have a value, use B instead.

Eric
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much.

Jeff
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic