aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax foriegn word issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax foriegn word issue" Watch "Ajax foriegn word issue" New topic
Author

Ajax foriegn word issue

Davidd Smith
Ranch Hand

Joined: Jul 28, 2003
Posts: 62
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 ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Is the response setting the correct character set coming back?

Eric
Davidd Smith
Ranch Hand

Joined: Jul 28, 2003
Posts: 62
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 28, 2003
Posts: 62
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

Joined: Jul 28, 2003
Posts: 62
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 28, 2003
Posts: 62
What a magic! It works. Thank you Eric.


Jeff
[ December 11, 2008: Message edited by: Davidd Smith ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 28, 2003
Posts: 62
Thank you so much.

Jeff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax foriegn word issue