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 :)

$(document).ready(function(){
$(".dc").html(' ');
  //["BTCUSD","ETHUSD","LTCUSD","XRPUSD","ZECUSD","XMRUSD"]
  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('

'+datara["Data"]["AggregatedData"]["PRICE"]+'

'); }); }; });
.digitalCurency{
  margin: 0;
  margin-top: 80px;
  padding:0;
}
.dc{
  width: 90vw;
  margin:auto;
}
.outershell{
  list-style: none;
  background: white;
  color: black;
  height:40vh;
  float: center;
  margin: 3px;
  padding: 1px;
 // min-width: 20%;
}
.headingsym{
  background: grey;
  color: white;
}



asked 1 min ago
Raza Hanafi

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

خبرنامه

عضویت

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