encoding problem with arabic character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • farukcse
    New Member
    • Nov 2007
    • 52

    encoding problem with arabic character

    Dear Sir,
    i am facing a problem with encoding for arabic characters.
    here is the code:
    1.test.html
    [HTML]<html>
    <body>

    <script type="text/javascript">
    var AJAX = {
    initialize: function(){
    var xmlHTTP;
    try{xmlHTTP = new XMLHttpRequest( );}
    catch(e){
    try{xmlHTTP = new ActiveXObject(" Msxml2.XMLHTTP" );}
    catch(e){
    try{xmlHTTP = new ActiveXObject(" Microsoft.XMLHT TP");}
    catch(e){
    alert("Your browser does not support AJAX!");
    return false;
    }
    }
    }
    return xmlHTTP;
    },

    get: function(url, func){
    var obj = this.initialize ();
    obj.open('GET', url, true);
    obj.send(null);
    obj.onreadystat echange = function(){
    if(obj.readySta te == 4){
    func(obj.respon seText);
    }
    }
    }
    }

    function getUpdate(txt){
    document.getEle mentById('getRe turn').innerHTM L = txt;
    }
    </script>

    <input type="text" id="test" name="test" value="blah" onkeyup="AJAX.g et('test.php?x= ' + this.value, getUpdate)" />
    <div id="getReturn"& gt;</div>


    </body>
    </html>
    [/HTML]
    2.test.php
    [CODE=php]<?php
    header('Content-Type: text/html; charset=utf-8');

    echo $_GET['x'];
    ?>
    [/CODE]
    ...
    if i put english character then there is no problem.
    ie. input: f f f output: f f f
    but if i put arabic character then i got error.
    i.einput: Õ Õ Õ
    output:? ? ?

    so can anyone tell me how to solve this problem?

    Regards,
    Faruk Chowdhury
    Last edited by gits; Nov 15 '07, 09:22 PM. Reason: added code tags
  • Dasty
    Recognized Expert New Member
    • Nov 2007
    • 101

    #2
    I did not check all code, but what you should fix the first is:
    [CODE=javascript]AJAX.get('test. php?x=' + encodeURICompon ent(this.value) , getUpdate)[/CODE]
    ^^ in case you are using utf-8 encoding

    but if you are working with 256 char encodings (like ANSI (win1250), ISO) use "escape" function instead of "encodeURICompo nent". Or you have to do encoding conversions in web server's side. I had the same problem few days ago. (I was using encodeURICompon ent and it did not work for windows1250 encoding) :( But you are using utf-8 so encodeURICompon ent should work fine.

    Try it and let me know ...

    Comment

    • farukcse
      New Member
      • Nov 2007
      • 52

      #3
      Dear Sir,
      Many Many Thanx for your cooperation . My problem is solved according to your code.

      Again Thanx to you.


      Regards,
      faruk chowdhury

      Comment

      • Dasty
        Recognized Expert New Member
        • Nov 2007
        • 101

        #4
        Originally posted by farukcse
        Dear Sir,
        Many Many Thanx for your cooperation . My problem is solved according to your code.

        Again Thanx to you.


        Regards,
        faruk chowdhury
        You are welcome. Nice to hear that it helped you ...

        Comment

        Working...