代码是这样的!
----------------index.php-----------------
$(document).ready(function(){
window.setTimeout(function () {
GetData()}, 4000);
});
function GetData(){//取值方法,参数i表示页数
$.getJSON("ajax/count_index.php",update_page);
}
function update_page(data){
$("#date").html(data.bmzs);
alert('dd');
} <div id="date"> </div>
-------------count_index.php----------------
$arraye=array("bmzs"=>rand(38, 49));
print_r (json_encode($arraye));
--------------------------------------------
不知为何,总是取不到返回的json数据,而且也不能定时刷新,数据!郁闷之极!
----------------index.php-----------------
$(document).ready(function(){
window.setTimeout(function () {
GetData()}, 4000);
});
function GetData(){//取值方法,参数i表示页数
$.getJSON("ajax/count_index.php",update_page);
}
function update_page(data){
$("#date").html(data.bmzs);
alert('dd');
} <div id="date"> </div>
-------------count_index.php----------------
$arraye=array("bmzs"=>rand(38, 49));
print_r (json_encode($arraye));
--------------------------------------------
不知为何,总是取不到返回的json数据,而且也不能定时刷新,数据!郁闷之极!
GetData()}, 4000); jQuery.getJSON("ajax/count_index.php","",update_page)
setInterval 间隔时间调用..
$("#date").text((new Date()).toString());
window.setTimeout(function () {
location.reload();
}, 1000);
});setTimeout 也可以实现,不过要循环调用自己。不过推荐用 setInterval