I have a Jquery code getting data from ajax call.
$.ajax({
type: 'GET',
url: 'php/upd_dashboard.php',
data: {'name': 'GET_ANUAL_TOTAL_OBJECTIF'},
success: function(data){
list_total_objectif=data;
},
dataType: 'JSON',
async: false
});
the file upd_dashboard.php, get data from MySql database, and return json result.
echo json_encode($result);
I have no problem when executing this code in localhost, but when I deploy the site I can't get the result of json_encode. by inspecting that in Chrome, I get a character '\ufeff' at the beginning of the json result !!
Is it a problem of encoding? Regards, Hamza.
答案 0 :(得分:1)
你可以尝试做ob_clean();在发送json输出之前
ob_clean();//clears the output buffer
echo json_encode($result);
但似乎你的$结果只是格格不入。它是字符串还是数组?无论如何,那里没有字符编码问题
答案 1 :(得分:0)
根据我在谷歌上发现的,\ ufeff是字节顺序标记。
因此,您可能已将您的PHP源文件包含在带有BOM的UTF-8中。
某些PHP版本不喜欢它并发送BOM输出。
尝试将所有PHP源文件转换为UTF-8而不使用BOM,它应该解决问题。