Javascript encoding (How to support Japanese characters) I18N

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eros
    New Member
    • Jun 2007
    • 66

    Javascript encoding (How to support Japanese characters) I18N

    [CODE=javascript]var xmlHttp;
    var m_placeholder;

    function executeProcess( serverscriptfil e, placeholder, posts) {
    alert(posts);
    xmlHttp=GetXmlH ttpObject();
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    m_placeholder = placeholder;
    var url=serverscrip tfile;
    //url=url+"?"+str ;
    url=url+"?sid=" +Math.random();
    xmlHttp.onready statechange=sta teChanged;
    //xmlHttp.open("G ET",url,true)
    //xmlHttp.send(nu ll)
    xmlHttp.open("P OST", url, true);
    xmlHttp.setRequ estHeader("Cont ent-Type", "applicatio n/x-www-form-urlencoded");
    //strPosts = buildPostReques t(posts);
    //xmlHttp.send(po sts);
    xmlHttp.send(po sts);
    }

    function stateChanged() {
    if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" )
    {
    document.getEle mentById(m_plac eholder).innerH TML=xmlHttp.res ponseText;
    }

    }
    }

    function GetXmlHttpObjec t() {
    var xmlHttp=null;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest( );
    }
    catch (e)
    {
    //Internet Explorer
    try
    {
    xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
    }
    catch (e)
    {
    xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
    }
    }
    return xmlHttp;
    }[/CODE]

    I implement the above code. The xmlHttp.respons eText contains Japanese characters.

    Problem: It returns all the information I need and also successfully put all the controls like textboxes, tables, labels but all the japanese characters was a garbaged.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Eros.

    You'll want to make sure that your server-side script outputs the string in the same character encoding as your HTML document.

    What programming language are you using server-side?

    Comment

    • eros
      New Member
      • Jun 2007
      • 66

      #3
      Originally posted by pbmods
      Heya, Eros.

      You'll want to make sure that your server-side script outputs the string in the same character encoding as your HTML document.

      What programming language are you using server-side?
      I am using PHP 5.
      And I am using HTML with the following code:
      [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      <html xmlns="http:?//www.w3.org/1999/xhtml" >
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=shift_j is">
      <head>
      <body>
      </body>
      </html>[/HTML]

      I am also use the PHP code in WML with the following code:
      [PHP]<?php
      header("Content-type: text/vnd.wap.wml");
      print "<?xml version=\"1.0\" encoding=\"Shif t-JIS\"?>";
      print '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
      "http://www.wapforum.or g/DTD/wml_1.1.xml">';
      ?>[/PHP]

      Comment

      Working...