我有一个json编码信息通过ajax加载的问题。jQuery ajax/post响应编码
的PHP代码(test.php的):
<?php
$val1 = 'Productmanager m/f';
$val2 = 'test';
$arr = array('first' => $val1, 'second' => $val2);
echo json_encode($arr);
?>
一个HTML文件中的JavaScript代码:
$(document).ready(function() {
$.post("test.php", function(data){
var response = $.parseJSON(data);
console.log(response.first);
console.log(response.second);
}
});
而结果在控制台的样子:
Productmanager m / f
和
test
这两个文件都是UTF-8编码。
我真的不知道为什么以及如何将其转换回可读的字符串。 你可能有一个想法如何发生?
我已经找到没有合适的解决方案了,先去搜索&替换方法。
我的回答已经更新。 – iambriansreed 2012-04-22 16:56:34
更新后正常工作! – Khazl 2012-04-22 17:03:28