CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    7

    encoding problem

    Dear Sir,

    i am facing a encoding problem in AJAX , it seems that it doesnt support multilanguage , i m trying to display Arabic text and i got '????'

    how can i solve this problem?please try to send a reply to me.

    Regards,
    Faruk Chowdhury

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: encoding problem

    When you send the contentType header, make sure you declare a character set that is compatible with Arabic. I believe UTF-8 contains Arabic.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2007
    Posts
    7

    Re: encoding problem

    Dear Sir,
    i added chracter set=utf-8 to both of my php file. but still am getting the same problem i.e i can't see my arabic characters. so can you tell me the way or code to set character set in javascript file for handling ajax request for sending data to php file .
    [code]
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>

    Regards,
    Faruk Chowdhury.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: encoding problem

    I said, when you send the headers. Declaring them in the client-side documents isn't enough.

    First, you need to declare them in any server-side document you are using. For PHP...

    PHP Code:
    header('Content-Type: text/html; charset=utf-8'); 
    Second, You might need to declare the Content-type header in the AJAX when you send it.

    Code:
    obj.open('POST', url, true);
    obj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
    obj.setRequestHeader('Content-length', parameters.length);
    obj.setRequestHeader('Connection', 'close');
    obj.send(parameters);
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2007
    Posts
    7

    Re: encoding problem

    Dear Sir,
    Thanx for your reply.
    still i am facing the same problem.
    my php and ajax code :

    1. file1.php
    PHP Code:
    <?php
    header
    ('Content-Type: text/html; charset=utf-8');
    ?>
    <?php
    echo "<form  name='form1'>
    Plate No:<input type='text' name='plate_no1' size = 1 maxlength =1>
        <input type='text' name='plate_no2' size = 1 maxlength =1>
        <input type='text' name='plate_no3' size = 1 maxlength =1>
        <input type='text' name='plate_no4' size = 1 maxlength =1>
        <input type='text' name='plate_no5' size = 1 maxlength =1>
        <input type='text' name='plate_no6' size = 1 maxlength =1>
        <input type='text' name='plate_no7' size = 1 maxlength =1>

    <input type='button' name = 'save' id='save' value='Save Data' onclick='SaveData();'>"
    ;
    ?>
    2. savedata.php
    PHP Code:
    <?php
    header
    ('Content-Type: text/html; charset=utf-8'); 
    ?>
    <?php
    $plate_no 
    $_GET['plate_no1']." ".$_GET['plate_no2']." ".$_GET['plate_no3']." ".$_GET['plate_no4']." ".$_GET['plate_no5']." ".$_GET['plate_no6']." ".$_GET['plate_no7'];

    echo 
    $plate_no;

    ?>
    3.file3.js
    Code:
    function SavaData() {
    var plate_no1 = document.form1.plate_no1.value;
    var plate_no2 = document.form1.plate_no2.value;
    var plate_no3 = document.form1.plate_no3.value;
    var plate_no4 = document.form1.plate_no4.value;
    var plate_no5 = document.form1.plate_no5.value;
    var plate_no6 = document.form1.plate_no6.value;
    var plate_no7 = document.form1.plate_no7.value;
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="save_policy.php"
    url=url+"?plate_no1="+plate_no1+ "&plate_no2="+plate_no2+ "&plate_no3="+plate_no3+ "&plate_no4="+plate_no4+ "&plate_no5="+plate_no5+ "&plate_no6="+plate_no6+ "&plate_no7="+plate_no7   
    url=url+"&sid="+Math.random();
    soapRequestStr='<?xml version="1.0" encoding="utf-8"?>';
    xmlHttp.onreadystatechange=stateChanged; 
    xmlHttp.open('GET',url,true);
    //xmlHttp.open("GET",url,true);
    xmlHttp.setRequestHeader('Content-type', 'text/xml;charset=utf-8');
    xmlHttp.setRequestHeader('Content-length',soapRequestStr.length);
    xmlHttp.setRequestHeader('soapRequestStr', 'close');
    xmlHttp.send(soapRequestStr);
    
    //xmlHttp.send(null)
    }
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("txtHint2").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;
    	}	
    	
    }
    e.g.
    if i send 9 2 3ص ص ص then i get the out pt from file2.php as 9 2 3 � �tml>

    if i set POST method in ajax and modify the varaible of file2.php with $_POST[''] then i get notice with alll of variable undefined..

    So. please can you tell me where is my error or how can i solve this?
    Please reply .
    Thanks in Advance.
    Regards,
    Faruk Chowdhury.
    Last edited by PeejAvery; November 14th, 2007 at 07:45 AM. Reason: Added code tags.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: encoding problem

    I have done much testing and so long as I supply the proper header in the PHP file, it works for me. Try the following attached zip file.
    Attached Files Attached Files
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured