Link to home
Start Free TrialLog in
Avatar of rospcc
rospcc

asked on

Thai characters and AJAX

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.

SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rospcc
rospcc

ASKER

tried that and it doesnt work
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
check database, what values it is storing?
Avatar of rospcc

ASKER

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?
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.
Avatar of rospcc

ASKER

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

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.
Avatar of rospcc

ASKER

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.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rospcc

ASKER

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.
Glad to help.