I making an ajax request on a json file then running a 'for loop' that loops through the file and displays the necessary information on a webpage. The function should also be displaying the result of a second ajax request in an html element. I can console.log the result but am unable to set the result into an html element.
I've tried various different approaches like creating arrays then pushing the results, everything I have tried failed.
HTML
$.getJSON("coins.json", function(result) {
for (var i = 0; i < result.length; i++) {
name = result[i].name;
ticker = result[i].ticker;
amount = result[i].amount;
icon = result[i].icon;
$('.coins').append("<div class='coin'><div class='cname'><img src='" + icon + "' /><h1>" + name + "</h1><p>Ticker : " + ticker + "< /
p > < h2 > "+$.getJSON(result[i].price, function(coinPrice){ console.log(coinPrice.ticker.price); })+" < /h2></div > < /div>");
}
});
Console outputs results properly but
$(this).text(coinPrice.ticker.price)
displays
[object Object]
coins.json
[
{
"name": "Bitcoin",
"ticker": "BTC",
"amount": 0.17,
"icon": "https://raw.githubusercontent.com/atomiclabs/cryptocurrency-icons/master/128/black/btc.png",
"price": "https://api.cryptonator.com/api/ticker/btc-aud"
},
{
"name": "Ethereum",
"ticker": "ETH",
"amount": 59,
"icon": "https://raw.githubusercontent.com/atomiclabs/cryptocurrency-icons/master/128/black/eth.png",
"price": "https://api.cryptonator.com/api/ticker/eth-aud"
},
{
"name": "Neo",
"ticker": "NEO",
"amount": 88,
"icon": "https://raw.githubusercontent.com/atomiclabs/cryptocurrency-icons/master/128/black/neo.png",
"price": "https://api.cryptonator.com/api/ticker/neo-aud"
}
]
I wish to select the price object in the coins.json make an ajax request and display its value in a html element. Please help