错误:
data[i].last_name is null
我检查了php的结果,其中“Beñas”触发了空值。
xhr.queue({
url: 'controller/agents_handler.php',
data: {load_request: 'top_earners'},
type: 'POST',
success: function(data) {
var data = JSON.parse(data);
var topEarnersDiv = $('.top_earners_container ul');
var str = "";
for ( i in data) {
str += '<p class="lastname boldthis">'+data[i].last_name.substr(0,8)+'</p>';
}
topEarnersDiv.html(str);
}
示例回复:
{
"user_id": "12345",
"user_name": "johnb",
"first_name": "john",
"last_name": null
}
来自php回复:
它的Beñas
值变为null
PHP:
$sql = "SELECT * FROM students WHERE x= active";
db::query($sql);
$mtd_list = array();
while ($rows = db::fetch_assoc()) :
$mtd_list[] = $rows;
endwhile;
return $mtd_list;
答案 0 :(得分:0)
这应该是一个编码错误,如果更改php代码,则应使用utf8_encode()
来解析该对象中的每个字符串。