I'm getting a JSON object (I think) back from my AJAX
call like this:
$.ajax({
url: 'testing.php',
type: 'POST',
data: {
code: code_got,
},
success: function(data) {
var list_data = data;
console.log(list_data);//this is the object shown below
var list_name = list_data['data']['name'];
console.log(list_name);//this throws an error that `name` is undefined
}
});
});
The response looks like this:
{
"total" : 5,
"data" : [
{
"id" : "312464ee1e",
"stats" : {
"members" : 58,
},
"web_id" : 11966492,
"name" : "List 1"
},
{
"id" : "312464ee1e",
"stats" : {
"members" : 123,
},
"web_id" : 1196649,
"name" : "List 2"
},
]
}
I'm trying to get (first off) the first list name. I've tried this, but it doesn't work:
var list_data = data;
console.log(list_data);//this is the object shown above
var list_name = list_data['data']['name']; //this throw an error "Uncaught TypeError: Cannot read property 'name' of undefined"
Second, I want to do an each
to get all of the name
items from the data, but I can't get to this until I figure out the JSON structure.
What am I doing wrong here?