I am trying to go through my json object and then print out the "name" value in a unordered list via a loop. I am trying to basically have an array of json objects each being a project name with different values under it such as project url and project image and so on. If someone could point me in the right direction on how to write this up that would be great.Any help would be awesome, thank you.
Here is my javascript:
$.ajax('projects.json', {
dataType: 'json',
success: function(result){
console.log(result.projectName.name.length);
for(var i=0;i<result.projectName.name.length;i++){
console.log("<li class='item'>"+result.projectName.name[i]+"</li>");
intro.find('ul').append("<li class='item'>"+result.projectName.name[i]+"</li>");
}
},
error: function(error){
alert("Error ajax not working"+error);
}
});
Here is my JSON:
{
"projectName": [{
"name": "shortSleeve",
"url": "www.google.com",
"color": "blue",
"ID": ""
},
{
"name": "slongSleeve",
"url": "www.yahoo.com",
"color": "red",
"ID": ""
},
{
"name": "turtleSleeve",
"url": "www.popsci.com",
"color": "purple",
"ID": ""
}]
}