Trying to pull info from one JSON datafeed and use that to make another API call, returning a second JSON string.
I am not able to make the second call properly.
Please note that my total JSON and JQUERY experience is about 4 days!
<HTML>
<head>
<script type="application/javascript" src="jquery-1.4.3.min.js"></script>
//Get Listing value for item 0 in JSON feed
$.getJSON('http://openapi.etsy.com/v2/public/shops/textilesandtreasures/listings/active?api_key=nshydhv462pr42t7g36b5nky',
function(data)
{
$('#ShopListing').html(data.results[0].listing_id);
$('Listing1').html(data.results[0].listing_id);
$.getJSON('http://openapi.etsy.com/v2/public/listings/'+data.results[0].listing_id+'/images?api_key=nshydhv462pr42t7g36b5nky',
function(data)
{
var $img1 = $("<img width='100%' />").attr('src', data.results[0].url_fullxfull);
$('#ItemImage').empty().append($img1);
});
});
})
</script>
</head>
<body>
<div id="ShopListing"></div>
<div id="ItemImage"></div>
</body>
</html>
Any help would be appreciated. Thanks.
getJSON uses XmlHttpRequest, meaning it’s an asycronous callback.
The solution:
Put the second JSON call in the callback for the first one.