im working with a JSON object here, i want to access the images, its an array within the array of 'results'. I know i have to loop, but not sure if im doing it correctly
My Code
function getVideos(art) {
$.ajax({
type: "GET",
url: 'http://imvdb.com/api/v1/search/videos?q=' + art,
dataType: 'json',
success: function (data) {
//alert(JSON.stringify(data.albums.name));
$('#videos').empty();
$.each(data.results.image, function (index, element) {
//alert(element.name);
$('#videos').append(element.results.image+ '<br/>');
});
},
error: function (data) {
$('#videos').html('<h3>Error in retrieval</h3>');
}
});
}
UPDATE when i just code
$.each(data, function (index, element) {
//alert(element.name);
$('#videos').append(element.results+ '<br/>');
});
i get
UPDATE:
it works for me now i just was accessing results instead of images
$.each(data.results, function (index, element) {
//alert(element.name);
$('#videos').append(element.image.o + '<br/>');
});
UPDATE:
it works for me now i just was accessing results instead of images
$.each(data.results, function (index, element) {
//alert(element.name);
$('#videos').append(element.image.o + '<br/>');
});
Your problem is in your $.each
you already take it down to the level of data.results.image
, and then you are looking for results.image
within that. So to your jQuery script you are looking for every single data.results.image.results.image
, and that doesn't exist. To loop through every results
object, you need to do an $.each
on data.results
then look for element.image
.
Here is a working JSFiddle which demonstrates this: http://jsfiddle.net/7udv3uoh/4/