2

i need to receive unicode string from php for my project, the best method that come to my mind was using ajax.

    $.ajax({
            url: './php_page.php', 
            data: 'action=get_sum_of_records&code='+code,
            datatype: 'json', 
            type: 'post',
            success: function(result){
                $('#block').html(result);
            }
    });

and in php_page.php page:

    echo '<table id="records" >';
    echo '<tr>';
    echo '<th>تاربخ</th>';
    echo '<th>نوع</th>';
    echo '<th>مبلغ</th>';
    echo '<th>حذف</th>';
    echo '</tr>';
    echo '</table>';

but sadly result was: �����

i used meta tag, contenttype in ajax, etc... nothing

  • you need to ensure the **ENTIRE** pipeline is utf-8. e.g. even if your php script properly spits out the right charsets/content-types, etc..., the page that your `.ajax()` is dumping out into must ALSO be utf8. – Marc B Dec 24 '15 at 16:16
  • Possible duplicate of [UTF-8 all the way through MySQL, PHP, and HTML](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through-mysql-php-and-html) – FirstOne Dec 24 '15 at 19:31

1 Answers1

1

From the jQuery Documentation:

contentType Default: 'application/x-www-form-urlencoded; charset=UTF-8'

When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it'll always be sent to the server (even if no data is sent). If no charset is specified, data will be transmitted to the server using the server's default charset; you must decode this appropriately on the server side.

Also check your file type it must be save in utf8 encoded, if you are using database, than your table column must be utf8 encoded.

devpro
  • 16,184
  • 3
  • 27
  • 38