I am trying to create a simple little jquery function that pulls JSON data from the url, then goes through each of the objects. All I want to do is to console.log the object.name so that I know that it is working. So far it is not working :( I checked the network tab in Chrome's Developer console and in the response it shows the json data was returned. The problem is I just can't get the object.name to console.log. If someone could help point out the problem I'd be greatful.
Here is the script:
function getJSON(){
$.ajax({
type: 'GET',
url: '/api/data.json',
success: function(data){
$.each(data, function(index, object){
console.log(object.name);
});
}
});
}
getJSON();
Here is the JSON data:
[
{
id: 1,
name: "Greg",
lastname: "Sugaro",
school: "Georgia Tech"
},
{
id: 2,
name: "Mike",
lastname: "Wilder",
school: "UGA"
}
]