S
S
sochi-russia2015-12-23 17:21:56
JavaScript
sochi-russia, 2015-12-23 17:21:56

There is an API request in the form of a link and there is an answer, how to issue it?

how to make js access by link and style the result (response) with css styles?
For example request:

http://api.travelpayouts.com/v2/prices/latest?currency=rub&period_type=year&page=1&limit=30&show_to_affiliates=true&sorting=price&trip_class=0&token=

The key is not specially written
Response:
{"success": true, "data": [{"show_to_affiliates":true,"trip_class":0,"origin":"IST","destination":"AYT","depart_date" :"2016-05-03","return_date":"2016-05-06","number_of_changes":0,"value":1458,"found_at":"2015-12-22T20:54:18+04: 00","distance":484,"actual":true}
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2015-12-23
@sochi-russia

HTML:

<div id='templates' style='display:none;'>
  <div class='latest-price'>
    <div class='price-value'></div>
  </div>
</div>

javascript:
$.getJSON(url,
                 function(dt){
                       if (dt.success){
                          var template = $('#templates > div');
                          var clone = template.clone();
                          clone.find('.price-value').text(dt.data[0].value);
                          clone.appendTo($('#parent-block'));
                       }
                 });

CSS:
.latest-price .price-value{
    color: red;
  }

<html>
  <body>
    <style>CSS</style>
    <div>
       <div id='parent-block'></div>
       Код выше
    </div>
    <script>Javascript </script>
  </body>
</html>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question