O
O
Oleg Galimov2018-03-14 09:01:46
JavaScript
Oleg Galimov, 2018-03-14 09:01:46

How to display the exchange rate in this ajax?

Good time of the day.
Tell me how to display the exchange rate in this ajax
Here is the ajax code

$.ajax({
  method: 'GET',
  url: 'js/currency.php',
  success: function(response){
    var json = JSON.parse(response);
    json.Valute.forEach(function(e){
      if (e['@attributes'].ID == 'R01235') console.log(e.Value);
    });
  }
});

Now prints the value to the console.
How to change the value, that is, now the value is 56.9359 , cut off the back digits in this case 59 and assign the value to a variable with output on the page?
Help with a solution.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Gorelov, 2018-03-14
@olegalimov

Here you can read how to round a number or bring it to the form you need.
To assign a number to a variable:
if (e['@attributes'].ID == 'R01235') var cur = e.Value;
And output this number to some input:
use jQuery
$('#id_iput').val(cur);

I
Ivan, 2018-03-14
@LiguidCool

jquery append would be the simplest solution.
As for string truncation, there are many solutions, but I would advise you to master regular expressions. A very powerful tool that is always needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question