Php 自动刷新div HTML/jQuery
我尝试使用jQuery刷新divPhp 自动刷新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() {
<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);