继承人的投票方式待办事项它,如果你唯一的希望抢时间。为什么有一个无限循环使用资源。
<?php
//polling.php
if(isset($_GET['poll']) && $_GET['poll']=='1'){
$out = array('thetime'=>date("F j, Y, g:i:s a"));
echo json_encode($out);
die;
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
function poll(){
setTimeout(function(){
$.ajax({ url: "http://localhost/polling.php?poll=1",cache: false,
success: function(data){
//Do something with returned json
$("#time").replaceWith("<p id=\"time\">The Server Time & Date is: "+ data.thetime +"</p>");
//Next poll
poll();
}, dataType: "json"});
// 1/2 a sec
}, 500);
}
$(document).ready(function(){
poll();
});
</script>
<p id="time">The Server Time & Date is: <?php echo date("F j, Y, g:i:s a");?></p>
佩塔提克瓦的在http://stackoverflow.com/questions/7740646/jquery-ajax-read-the-stream-incrementally该解决方案的答案工作的请客我 – 2016-08-08 13:44:37