0

I try to get a div refreshed with jQuery.

<div class="col-lg-8" id="btc"> Send <?php echo $bitcoin_price; ?></div>

<script>
    $(document).ready(function () {
        var interval = setInterval(refresh, 5000);
    });

    function refresh() {
        $.get('site', function (result) {
            $('#btc').html(result);
        });
    }
</script>


$bitcoin_price:

$url = "https://bitpay.com/api/rates";

$json = file_get_contents($url);
$data = json_decode($json, true);

// $data[1] = USD
$rate          = $data[1]["rate"];
$usd_price     = 10;     # Let cost of elephant be 10$
$bitcoin_price = round($usd_price / $rate, 8);

Anyone knows how to to get this div refreshed with an interval and execute the request?

Or is this not possible? Do i need to include and refresh a file with ajax?

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
Ronnie Oosting
  • 1,252
  • 2
  • 14
  • 35

1 Answers1

1

This php code has to be called from ajax:

$url = "https://bitpay.com/api/rates";

$json = file_get_contents($url);
$data = json_decode($json, true);

// $data[1] = USD
$rate          = $data[1]["rate"];
$usd_price     = 10;     # Let cost of elephant be 10$
$bitcoin_price = round($usd_price / $rate, 8);

You have to call it from your refresh function and that'd would do the work.

Jefferson
  • 794
  • 10
  • 24