PHP/AJAX:无法在ajax响应中显示外来字符
问题描述:
在我的数据库中,我有外国名称的特殊字符。我在正常输入中使用了<meta charset="utf-8">
这个特殊字符在html中正常工作。然而,当我打电话Ajax请求,并使用HTML(数据)显示特殊字符转化为具体的div,文本正在改变,以????? ??????? ?????
如何解决这个PHP/AJAX:无法在ajax响应中显示外来字符
HTML
<div id="country_info"> </div>
JS
$(document).on('change','#country_list', function(){
var thisVal_id = $(this).val();
$.ajax({
url:'../ajax/paraphernalia/ajax_displayCountry_info.php',
type:'post',
data: {thisVal_id : thisVal_id , event_id : event_id},
cache : false,
success : function(data){
$('#country_info').html(data);
}
});
});
response.php
//this select option contains different foreign characters
$output .= '<select id="official_name" class="form-control" style="padding:0px; !important">';
while($row1 = mysql_fetch_assoc($sql1)){
$output .= '<option value="'.$row1['name_official'].'">'.$row1['name_official'].'</option>';
}
$output .= '</select>';
echo $output;
答
只是做一个小的改变,这适用于我..
$output .= '<select id="official_name" class="form-control" style="padding:0px; !important">';
while($row1 = mysql_fetch_assoc($sql1)){
$name=mb_convert_encoding($row1['name_official'], 'HTML-ENTITIES', 'utf-8')
$output .= '<option value="'.$name.'">'.$name.'</option>';
}
$output .= '</select>';
echo $output;
你可能想看到这个计算器[答案](http://stackoverflow.com/a/14397845/6823486)。希望能帮助到你!! – Bharath
谢谢你,但我解决了我的问题,使用'mysql_set_charset(“UTF8”);'把我的每一页顶部 –