实时刷新

js

<script type="text/javascript" src="jquery.js"></script>
<script>
$(function(){
    window.setInterval(function(){
        $.getJSON("json.php",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:31  fleam  阅读(212)  评论(0编辑  收藏  举报