Japanese charset support in GetXmlHttpObject()

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

    Japanese charset support in GetXmlHttpObject()

    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.dt d">
    <html xmlns="http:?//www.w3.org/1999/xhtml" >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=shift_j is">
    ......[/HTML]

    Code:
    var xmlHttp;
    var m_placeholder;
    
    function executeProcess(serverscriptfile, placeholder, posts) {
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        m_placeholder = placeholder;
        var url=serverscriptfile;
        url=url+"?sid="+Math.random();
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=Shift-JIS'");
        xmlHttp.send(posts);
    }
    
    function stateChanged() {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
            document.getElementById(m_placeholder).innerHTML=xmlHttp.responseText;
        }
    }
    
    function GetXmlHttpObject() {
        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.XMLHTTP");
            }
        }
        return xmlHttp;
    }
  • eros
    New Member
    • Jun 2007
    • 66

    #2
    Japanese charset support in GetXmlHttpObjec t()

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

    I think the problem is during GetXmlHttpObjec t 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
    Code:
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=shift_jis'");
    PHP code
    [PHP]header('Content-Type: text/html; charset=shift_j is');[/PHP]

    HTML code
    [HTML]<meta http-equiv="Content-Type" content="text/html; charset=shift_j is">[/HTML]

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      See if this link helps.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Merged threads.

        Comment

        • eros
          New Member
          • Jun 2007
          • 66

          #5
          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.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Glad you got this working. I'm sure your other problem will be solvable too.

            Comment

            Working...