0👍
Okay it can be seen that your data is actually included in data.data
because data
variable contains a property with the name of data
Also there is another flaw in your code. In javascript we can’t iterate items of an array with for (var i in arr)
(this can only be used to iterate through keys of an object)
So you should change the for
part of your code to the following
var arr = data.data;
for(var i=0;i<arr.length;i++) {
item = arr[i];
players.push("Player " + item.first_name);
ages.push(item.age);
}
Indeed it’s better to rename the variable named data
to response
:
$.ajax({
url: "staff.php",
method: "GET",
success: function(response) {
console.log(response.data);
})
Source:stackexchange.com