【发布时间】:2018-08-15 15:00:03
【问题描述】:
我有这个,从 laravel API 创建的数据 json
[
[{
"id": 4,
"name": "Customer-izlgy",
"email": "ycgjl@xxyin.com"
}, {
"id": 5,
"name": "Customer-bkxjn",
"email": "wlrew@iloiv.com"
}],
[{
"id": 1,
"name": "Customer-izlgyt",
"email": "ycgjl@xxysdin.com"
}, {
"id": 2,
"name": "Customer-bkxjnyf",
"email": "wlrew@iloifsv.com"
}]
]
我试图通过 ajax 获取数据 id 4 和 id 1,但总是出错 Uncaught TypeError: Cannot read property 'name' of undefined
这是我从上述数据 json 中获取名称的代码。
// get customer data that has been handled
function callHandledCustomer() {
$.ajax({
type: "GET",
url: rootUrl + "/api/chat/getHandledCustomer",
dataType: "json",
success: function(response){
$.each(response, function(i, customer) {
console.log(customer[0][0].name); // get name
});
}
});
}
非常感谢
【问题讨论】: