Мой report.php возвращает файл json. Это мой JavaScript, чтобы попробовать и прочитать его:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function () {
var data;
$.ajax({
type: 'POST',
dataType: 'json',
url: 'report.php',
data: data,
success: function (data) {
console.log(data[0].name);
}
});
});
</script>
JSON
{
"report": {
"type": "realtime",
"elements": [{
"id": "datetime",
"name": "Date"
}, {
"id": "page",
"name": "Page"
}],
"reportSuite": {
"id": "myID",
"name": "GD"
},
"period": "2018-08-31T08:31:26+0100\/2018-08-31T10:31:26+0100",
"metrics": [{
"id": "instances",
"name": "Instances",
"type": "number",
"decimals": 0
}],
"data": [{
"name": "2018-08-31T08:31:26+0100",
"year": 2018,
"month": 8,
"day": 31,
"hour": 8,
"minute": 31,
"breakdown": [{
"name": ":A",
"trend": "-91933.00",
"counts": ["946801"]
}, {
"name": ":A Overview",
"trend": "-97580.00",
"counts": ["692229"]
}, {
"name": ":Successfull",
"trend": "-39664.00",
"counts": ["587378"]
}, {
"name": ":Trans",
"trend": "-64227.00",
"counts": ["440308"]
}, {
"name": ":Login",
"trend": "-21233.00",
"counts": ["367356"]
}, {
"name": ":Login - Enter Passcode",
"trend": "-20456.00",
"counts": ["334372"]
}, {
"name": ":Login - Complete",
"trend": "-20724.00",
"counts": ["321480"]
}, {
"name": ":Logiln - Complete",
"trend": "-19448.00",
"counts": ["291264"]
}, {
"name": "Li6",
"trend": "-6278.00",
"counts": ["100971"]
}],
"breakdownTotal": ["7118755"]
}, {
"name": "2018-08-31T09:31:26+0100",
"year": 2018,
"month": 8,
"day": 31,
"hour": 9,
"minute": 31,
"breakdown": [{
"name": ":Accounts",
"trend": "-91933.00",
"counts": ["854868"]
}, {
"name": ":Overview",
"trend": "-97580.00",
"counts": ["594649"]
}, {
"name": "Li6",
"trend": "-6278.00",
"counts": ["94693"]
}],
"breakdownTotal": ["6613117"]
}],
"totals": ["13731872"],
"version": "1.4.17.2"
}
}
Вместо того, чтобы печатать JSON в консоли, я получаю эту ошибку:
Uncaught TypeError: Cannot read property 'name' of undefined
at Object.success (index.php:23)
at c (jquery-1.9.1.min.js:3)
at Object.fireWith [as resolveWith] (jquery-1.9.1.min.js:3)
at k (jquery-1.9.1.min.js:5)
at XMLHttpRequest.r (jquery-1.9.1.min.js:5)
Может кто-нибудь, пожалуйста, помогите мне понять, почему?