By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

Japanese charset support in GetXmlHttpObject()

P: 66
Please tell everybody on how to support different languages using AJAX. I've been searching this for a long time in many forums in the internet but they did not solved or post the definite solutions.

Here's the printscreen: (please do copy and paste if not displayed here.)

output via php and html (http://anime.geocities.jp/rozvinbm_jp/shops.JPG)



output via php, html and processed with Ajax (http://anime.geocities.jp/rozvinbm_jp/shopsajax.JPG)




In addition, here is my code to explicitly defined the encoding:
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http:?//www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
......[/HTML]

Expand|Select|Wrap|Line Numbers
  1. var xmlHttp;
  2. var m_placeholder;
  3.  
  4. function executeProcess(serverscriptfile, placeholder, posts) {
  5.     xmlHttp=GetXmlHttpObject();
  6.     if (xmlHttp==null)
  7.     {
  8.         alert ("Browser does not support HTTP Request");
  9.         return;
  10.     }
  11.     m_placeholder = placeholder;
  12.     var url=serverscriptfile;
  13.     url=url+"?sid="+Math.random();
  14.     xmlHttp.onreadystatechange=stateChanged;
  15.     xmlHttp.open("POST", url, true);
  16.     xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=Shift-JIS'");
  17.     xmlHttp.send(posts);
  18. }
  19.  
  20. function stateChanged() {
  21.     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  22.     {
  23.         document.getElementById(m_placeholder).innerHTML=xmlHttp.responseText;
  24.     }
  25. }
  26.  
  27. function GetXmlHttpObject() {
  28.     var xmlHttp=null;
  29.     try
  30.     {
  31.         // Firefox, Opera 8.0+, Safari
  32.         xmlHttp=new XMLHttpRequest();
  33.     }
  34.     catch (e)
  35.     {
  36.         //Internet Explorer
  37.         try
  38.         {
  39.             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  40.         }
  41.         catch (e)
  42.         {
  43.             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  44.         }
  45.     }
  46.     return xmlHttp;
  47. }
Aug 25 '07 #1
Share this Question
Share on Google+
5 Replies


P: 66
When the AJAX calls the php file, I've noticed the data in the $_POST are garbage data.

I think the problem is during GetXmlHttpObject execution to past the Posted data to php file.

Please teach me to set the charset in AJAX supporting Japanese charset.

Currently, I am using the following settings:

PostgreSQL ver 7.4.1 encoding: UNICODE

Javascript/AJAX code
Expand|Select|Wrap|Line Numbers
  1. xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=shift_jis'");
PHP code
[PHP]header('Content-Type: text/html; charset=shift_jis');[/PHP]

HTML code
[HTML]<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">[/HTML]
Aug 27 '07 #2

acoder
Expert Mod 15k+
P: 16,027
See if this link helps.
Aug 27 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Merged threads.
Aug 27 '07 #4

P: 66
I cannot install the mbstring functions.
But I found iconv function.. it works well.

here's the php code:
[php]$str = iconv("UTF-8", "SJIS", $str);[/php]

I do the above code upon calling the php file by the XMLHttpRequest.

I have new problem when I release from the debugging season (on production). I will post new topic because it is not related in encoding.

Thank you very much.
Aug 28 '07 #5

acoder
Expert Mod 15k+
P: 16,027
Glad you got this working. I'm sure your other problem will be solvable too.
Aug 28 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.