German character issue

Discussion in 'PHP' started by vetrivel, Mar 9, 2010.

  1. #1
    Hi,
    I am using the multi language in a site and it is working fine.
    But during the ajax call the correct content is not getting displayed.

    EX:
    This is the content and it is loading correctly on page load.
    "Elégance"

    But during the ajax call the text is broken and showing as
    "El�gance"


    and in mozilla it is showing as QUESTION INSIDE THE DiAMOND .


    I have added the charset ISO-1859-1 in the
    php file (mb_ internal_ encoding ("ISO-8859-1");)

    Js file as
    xmlHttp . setRequestHeader("Content-Type", "text/plain;charset=UTF-8");

    My question is why is it working fine on page load and not in the ajax call.?


    Please advice me.
     
    vetrivel, Mar 9, 2010 IP
  2. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    anybody have this problem.
    or faced this kind of issue.
    and is my above post clear?
     
    vetrivel, Mar 10, 2010 IP
  3. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #3
    tried changing the charset of the JS to ISO? why you use a different charset there?

    and why using "é" anyway? its not a german character, if iam not wrong its used in french
     
    Basti, Mar 10, 2010 IP
  4. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeap..I dont know how to fix this issue ,So i tried all the possibilities to fix it.
    Thats the reason i changed the js charset too.
    And yes it is french one ,I am in confused state.

    Do u have any idea?
    why it is occuring in the ajax call only.
     
    vetrivel, Mar 11, 2010 IP
  5. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #5
    Hmm ive read this, ill try to search a bit on how to fix it, but it seems that is your problem, your ajax need to be ISO, but

    "AJAX calls are always UTF-8 encoded because
    a) the browser internally uses the character encoding of the OS and
    b) javascript uses UTF-8. UTF-16 is commonly used for internal character encoding by many OS-es, e.g. Windows.

    So when the AJAX call is made the browser converts the UTF-16 encoding (loss less) to UTF-8. setForm() urlencodes the form using this UTF-8 encoding, regardless of what the character encoding of the HTML page is or what character encoding the user has chosen in the browser."

    So you need to decode your sended data either using
    utf8_decode function, which convert characters sent using utff8 to iso
    or using
    application/x-www-form-urlencoded;charset=UTF-8 when the data is sent using ajax

    But dont ask me how to implement that :p
     
    Last edited: Mar 11, 2010
    Basti, Mar 11, 2010 IP