?
Solved

Thai characters and AJAX

Posted on 2007-11-28
13
Medium Priority
?
1,211 Views
Last Modified: 2008-02-01
Hi all,

Our JSP application accepts Thai as the input and will display back to the user their input. Those inputs will be stored in to the Database. The application is running on Resin. Not long ago, we implemented Ajax into our application and the Thai characters is not being stored properly. It was stored and displayed as ?????.

Is it caused by Ajax? What kind of encodings is required? Currently, in the jsp page, we specify <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


Thanks all for the help.

0
Comment
Question by:rospcc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 60 total points
ID: 20364595
>  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

try changing it to utf8
0
 

Author Comment

by:rospcc
ID: 20364672
tried that and it doesnt work
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 60 total points
ID: 20364746
Can you add some debug to check it is the ajax -> java boundary that is causing the issues?

How is the ajax implemented?  Are you using something like DWR?

Have you seen this thread:  http://lists.evolt.org/pipermail/javascript/2006-August/011076.html

It talks about PHP, but the same problem...

They ended up encoding their data with a Base64 implementation http://www.webtoolkit.info/javascript-base64.html

But as that thread says, that isn't finding the problem...it's just working round it

Tim
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 60 total points
ID: 20365045
And if you set the content charset to utf-8 the DATA needs to be utf-8 too and not windows-874, ISO-8859-11, tis-620  or whatever

http://www.fileformat.info/info/unicode/block/thai/utf8test.htm
0
 
LVL 11

Expert Comment

by:Manish
ID: 20365185
check database, what values it is storing?
0
 

Author Comment

by:rospcc
ID: 20370194
We are Ms SQL 2000. The column is set to NVarchar type.

Without going through AJAX, the Thai characters can be stored and viewed correctly. In the database, it's being stored as something like this: &#80&#97&#115&#115&.

However, when we let the saving goes through AJAX, the Thai characters was stored as ???? instead. Is there any proceesing or conversion done within the AJAX layer?
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 20376912
You should post your Ajax code.

The HTML content type -- which if you've left it as iso-8859-1 is wrong: it should be utf-8 as "objects" said -- matters for setting variables in Javascript.  If your data is being handed around as Javascript vars, then that might be why the values are incorrectly encoded when they are submitted through the Ajax calls.
0
 

Author Comment

by:rospcc
ID: 20400452
Yes. The data is being passed to Javascript. Is that the cause of the problem? Any encoding we can specify in javascript?
function confirmSave(type, messageToDisplay)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	}
	
	var clicked = false;
	
	if(confirm(messageToDisplay)) {
		clicked = true;
	} else {
		return false;
	}
	
         var url	="GetQuestions.jsp"
	url=url+"?go=3&finish=" + type
	if (document.getElementById( "qeustionID" ) != null && document.getElementById( "questionID" ).value != "") {
		var questionIDtemp = "" + document.Question.questonID.value
		var questionID = questionIDtemp.split(",")
		
		for(i=0; i < questionID.length; i++) {
			if (document.getElementById( questionID[i] ).value != "") {
				url=url+"&" + questionID[i] + "=" + document.getElementById( questionID[i] ).value;
			}
		}
	}
}

Open in new window

0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 20401127
It looks as if you are not putting quotes around your values in the Javascript.  If you don't explicitly put quotes around them, and the values look possibly numeric, Javascript attempts to read the values as numbers, which is probably where the ???? is coming from.
0
 

Author Comment

by:rospcc
ID: 20408560
Currently, we store the thai characters as &#80&#97&#115&#115&. If we use utf-8, it will store the Thai characters as it is.  The problem will be solved once we changed how the Thai characters are stored in our DB. However, we are not planning to do so in the near future because it required major revamping.

With iso-8859-1, we have checked that ??? problem occured when we read the parameters from the javascript url. When we called request.getParameter() of one of the url parameters, it will return ????. If we did not read from the url, i.e. calling request.getParameter() of the field of the form itself, it will return &#80&#97&#115&#115&.

With utf-8, when we called request.getParameter() of one of the url parameters and calling request.getParameter() of the field of the form itself, it will return the thai characters.  However, we do not want to store characters. We need to store the thai characters as &#80&#97&#115&#115&.

My question is how can i convert thai characters to this from &#80&#97&#115&#115& using javascript?
We are thinking to convert the thai characters in javascript before passing it as parameter.

0
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 1320 total points
ID: 20409667
>>thai characters as &#80&#97&#115&#115&.

Those characters are encoded "Pass", which is not Thai.  To help everyone debug, we should probably be looking at real Thai characters, for example:
&#3607;&#3615;&#3614;&#3629;&#3619;&#3639;

If you're passing your Thai value as a parameter on the URL, then you should encode the value.  It doesn't look as if you're doing that.  

If you still want to turn your input Thai chars into the Unicode entity representations (e.g., &#[1234];) in the Javascript before passing them as a parameter, then this person has written a set of Javascript functions to do that:
http://www.kadifeli.com/fedon/utf.htm

Do a view source to see the functions he has created.
0
 

Author Comment

by:rospcc
ID: 20410093
Thank you mrcoffee365. I have managed to store my Thai characters correctly by encoding the Thai characters before passing it as parameters.

Just wondering, is there other better way of doing it? If there isnt then i will close this question tomorrow evening.
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 20412328
Glad to help.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question