Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自动刷新div HTML/jQuery_Php_Jquery_Html - Fatal编程技术网

Php 自动刷新div HTML/jQuery

Php 自动刷新div HTML/jQuery,php,jquery,html,Php,Jquery,Html,我尝试使用jQuery刷新div <div class="col-lg-8" id="btc"> Send <?php echo $bitcoin_price; ?></div> <script> $(document).ready(function () { var interval = setInterval(refresh, 5000); }); function refresh() {

我尝试使用jQuery刷新div

<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>
有人知道如何每隔一段时间刷新这个div并执行请求吗


或者这是不可能的?是否需要使用ajax包含并刷新文件?

必须从ajax调用此php代码:

$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);
您必须从刷新函数调用它,这样就可以完成工作

$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);