1

我正在使用 ajax 分页方法来搜索结果。在设置要连接的mysql项目并为此设置utf8之后,我的结果是'nt utf8 unicode,

我的 dabtabase 数据是 utf8 并且正确保存。但是在获取后我无法使用正确的 unicode。

我在本地主机上没有问题,但是在服务器上上传文件后我有问题

查询:

$(document).ready(function(){
    $('#searchWordButton').click(function(){
        searchWord = $('#searchWord').val();
        if ( $.trim(searchWord) =='' ){
            alert('input is empty...');
            return false;
        } 
        else{
        $('[id^="hidden_div"]').hide();
            $('.div_search').show();                
            function loadData(page){
                $.ajax
                ({
                    type: "POST",
                    url: "load_data.php",
                    data: "page="+page+"&word="+searchWord,
                    success: function(msg)
                    {
                        $("#search_container").html(msg);
                    }
                });
            }
            loadData(1);  // For first time page load default results
            $('#search_container').on('click','.pagination li.active',function(){
                var page = $(this).attr('p');
                loadData(page);
            });                             
        }

    });

PHP load_data.php :

<?php
if($_POST['page'])
{
$page = $_POST['page'];
$word = $_POST['word'];
$cur_page = $page;
$page -= 1;
$per_page = 22;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;

include 'config.inc';

$linkConnection = mysql_connect (LOCALHOST , USERNAME , DBpass);
mysql_query("set charset set utf8", $linkConnection);
mysql_query("set names 'utf8'", $linkConnection);           
mysql_select_db(DBname);

$query_pag_data = "SELECT id as msg_id ,subject as message , description from contents WHERE subject like '%$word%' LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());


$msg = "";
while ($row = mysql_fetch_array($result_pag_data)) {
    $subject     = htmlentities(htmlspecialchars_decode($row['message']));
    $description = htmlentities(htmlspecialchars_decode($row['description']));

    $msg .= "<div style='font-weight:bold;color:#063B27;'><a href='viewPage.php?topicID={$row['msg_id']}'>".$subject . "</a></div>";
    $msg .= "<div style='color:#378686;padding-right:30px;'>".mb_substr($description,0,200,'UTF-8').' ...' . "</div>";
}
$msg = "<div class='data'>" . $msg . "</div>"; // Content for Data

$query_pag_num = "SELECT COUNT(*) AS count FROM contents WHERE subject like '%$word%' ";
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);

if ($cur_page >= 7) {
    $start_loop = $cur_page - 3;
    if ($no_of_paginations > $cur_page + 3)
        $end_loop = $cur_page + 3;
    else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
        $start_loop = $no_of_paginations - 6;
        $end_loop = $no_of_paginations;
    } else {
        $end_loop = $no_of_paginations;
    }
} else {
    $start_loop = 1;
    if ($no_of_paginations > 7)
        $end_loop = 7;
    else
        $end_loop = $no_of_paginations;
}

$msg .= "<div class='pagination'><ul>";

// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
    $msg .= "<li p='1' class='active'>ابتدا</li>";
} else if ($first_btn) {
    $msg .= "<li p='1' class='inactive'>ابتدا</li>";
}

// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
    $pre = $cur_page - 1;
    $msg .= "<li p='$pre' class='active'>صفحه قبل</li>";
} else if ($previous_btn) {
    $msg .= "<li class='inactive'>صفحه قبل</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {

    if ($cur_page == $i)
        $msg .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
    else
        $msg .= "<li p='$i' class='active'>{$i}</li>";
}

// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
    $nex = $cur_page + 1;
    $msg .= "<li p='$nex' class='active'>صفحه بعد</li>";
} else if ($next_btn) {
    $msg .= "<li class='inactive'>صفحه بعد</li>";
}

// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
    $msg .= "<li p='$no_of_paginations' class='active'>انتها</li>";
} else if ($last_btn) {
    $msg .= "<li p='$no_of_paginations' class='inactive'>انتها</li>";
}
$total_string = "<span class='total' a='$no_of_paginations'>صفحه <b>" . $cur_page . "</b> از <b>$no_of_paginations</b></span>";
$msg = $msg . "</ul>"  . $total_string . "</div>";  // Content for pagination

echo $msg;
    }

结果 :

ع�د سع�د �طر در ب�تاز�

ر�ز د�ش�ب� 30ش�ر��ر1388 �& ...

ØÙ�Ù�Ù� Ù�اÙ� Ø´Ù�اÙ� Ù� عÛ�د سعÛ�د Ù�طر Ù�بارک با د

«اÙ�Ù�Ù�Ù� صÙ�Ù� عÙ�Û� Ù�ØÙ�Ù�د Ù�&Osla ...

4

1 回答 1

1

尝试在之后添加此行<?php

header('Content-Type: text/plain; charset=utf-8');
于 2013-08-15T12:46:02.673 回答