I am trying to make a simple currency converter! I take the exchange rate from https://fixer.io via Api

//Load value $.ajax({ url: 'http://data.fixer.io/api/latest?access_key={!KEY!}', dataType: 'jsonp', success: function(json) { for(let key in json.rates){ $('.changeLoad').append('<option>'+key+'</option>') } } }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select name="change" class="changeLoad" id="changeValuteFrom"> </select> 

In select from ip currency! Then I try to take a click on the value and get the value of the currency but in the end I get undefined!

 $.ajax({ url: 'http://data.fixer.io/api/latest?access_key={!KEY!}', dataType: 'jsonp', success: function(json) { for(let key in json.rates){ $('.changeLoad').append('<option>'+key+'</option>') } } }); $('#js-exchange-start').click(function(){ let changeValuteFrom = $('#changeValuteFrom').val(); $.ajax({ url: 'http://data.fixer.io/api/latest?access_key={!KEY!}', dataType: 'jsonp', success: function(json) { console.log(json.rates); console.log(json.rates.RUB); console.log(json.rates.changeValuteFrom); //undefined } }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select name="change" class="changeLoad" id="changeValuteFrom"> </select> <button class="btn" id="js-exchange-start"><i class="fas fa-dice-d20"></i> Обменять</button> 

  • So there is no such object, show Response which returns the server. - EVG
  • So the fact is that if I write manually json.rates.VALUE, then in the end I get the desired value. console.log (json.rates.RUB) - I will get the values ​​75 ...... And if I also take the values ​​from the box console.log (json.rates.changeValuteFrom) - I will get the undefined - JuniorCoder
  • one
    Because so: json.rates[changeValuteFrom] - Vladimir Klykov
  • If you change to json.rates [changeValuteFrom] the same undefine - JuniorCoder 5:47 pm
  • So changeValuteFrom contains a key name which is not in json.rates Show the output of this code here: console.log('1)'+json.rates.[changeValuteFrom]);console.log('2)'+changeValuteFrom); - Vladimir Klykov

0