API data appending to last DIV | بلاگ

API data appending to last DIV

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

So I am getting prices from this API, https://min-api.cryptocompare.com/data/top/exchanges/full?fsym=BTC&tsym=USD. I am going through a loop to append these to their divs. The var total should be changing on each loop but it all seems to be appending to the last DIV. Is it because the loop has already moved on before the data comes back from the api? If so is there a way to make the loop wait? Thanks :)

$(".dc").html(' ');
  var crypto= [{total:"btcusd", from:"BTC", to:"USD"},
                {total:"ethusd", from:"ETH", to:"USD"},
                {total:"ltcusd", from:"LTC", to:"USD"},
                {total:"xrpusd", from:"XRP", to:"USD"},
                {total:"zecusd", from:"ZEC", to:"USD"},
                {total:"xmrusd", from:"XMR", to:"USD"}];

      for (var i=0; i
'); $("."+crypto[i].total).append('

'+crypto[i].from+' - '+crypto[i].to+'

'); var total= crypto[i].total; var cryptos="https://min-api.cryptocompare.com/data/top/exchanges/full?fsym="+crypto[i].from+"&tsym="+crypto[i].to+""; //var detail; $.getJSON(cryptos, function(datara){ var detail= datara["Data"]["AggregatedData"]["PRICE"]; detail.toString(); console.log(total); $("."+total).append('


'); }); }; });
  margin: 0;
  margin-top: 80px;
  width: 90vw;
  list-style: none;
  background: white;
  color: black;
  float: center;
  margin: 3px;
  padding: 1px;
 // min-width: 20%;
  background: grey;
  color: white;

asked 1 min ago
Raza Hanafi

نویسنده : استخدام کار بازدید : 6 تاريخ : سه شنبه 29 اسفند 1396 ساعت: 8:52

آرشیو مطالب



نام کاربري :
رمز عبور :