js 实时数据显示

js代码

<script type="text/javascript" src="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\"
}";
?>

 

posted @ 2017-01-22 17:21  fleam  阅读(1389)  评论(0编辑  收藏  举报