首页 > 代码库 > js 实时数据显示

js 实时数据显示

js代码

<script type="text/javascript" src="http://www.mamicode.com/jquery.js"></script>
<script>
$(function(){
    window.setInterval(function(){
        $.getJSON("json.php",{"code":"<?php echo $fundcode ?>","rand":Math.random()},function(data){
            document.getElementById(‘ceshi‘).innerHTML = data.name+data.price;
        });
    },1000);
});
</script>

<div id="ceshi"></div>

php代码

<?php

$price = rand(10,100);

echo "{
    \"name\": \"铜\",
    \"price\": \"".$price."\",
    \"diff\": \"++146\",
    \"diffRate\": \"++0.37%\",
    \"jk\": \"39487\",
    \"zk\": \"39445\",
    \"zg\": \"39977\",
    \"zd\": \"39127\",
    \"class\": \"39591\"
}";
?>

 

js 实时数据显示