dongying2112 2018-10-06 17:08
浏览 38
已采纳

通过ajax正确显示MySQL和PHP中的汉字

How to properly display Chinese characters in HTML through ajax using PHP?

In the MySQL I have this data èŠ±æ ·å¹´åŽ, if I use PHP echo it shows 花样年华, but if I use ajax callback I get èŠ±æ ·å¹´åŽ (eventname), the ajax code is as below:

$.ajax({
    url: "action/getEvent.php",
    type: "POST",
    data: {'LoadEvent':''},
    dataType: "json",
    success: function(data) {
        if(data.eventname!=''){
            alert(data.eventname);
        }
    },
    error: function (xhr, ajaxOptions, thrownError) {
        console.log(xhr);
    }
});

Is it I need to do something on the data before saving into MySQL database? But why PHP is ok only ajax is not?

  • 写回答

1条回答 默认 最新

  • dstbp22002 2018-10-06 22:00
    关注

    Could you try to set UTF-8 charset encoding on all of code sides, like AJAX requests[optional], PHP files with header() function, html files and also MySQL table fields charsets.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?