wiki:waue/2011/0825
  • record_count.php
<?php
date_default_timezone_set('ROC');
echo date("D M j G:i:s T Y");
?>
  • demo1.html
<!doctype html>

<meta charset="UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#MyRefresh').load('record_count.php').fadeIn("slow");
}, 2000); // refresh every 10000 milliseconds
</script>

<title> waue </title>
<body>
<div id="MyRefresh"> 每兩秒重新導入資料 </div>
</body>

  • demo2.html
<!doctype html>

<meta charset="UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">

function updateFun() {
  $.ajax({
    type: 'GET',
    url: 'record_count.php',
    timeout: 2000,
    success: function(php_data) {
      $("#some_div").html(php_data);
      $("#notice_div").html('waue'); 
      window.setTimeout(updateFun, 1000);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      $("#notice_div").html('Timeout contacting server..');
      window.setTimeout(updateFun, 60000);
    }
});
}
$(document).ready(function() {
    updateFun();
});

</script>

<title> waue </title>
<body>
<table>
<tr>
<td> 使用者 </td><td> 說明 </td><td> 時間 </td>
</tr>
<tr>

<td><div id="notice_div"> </div></td>
<td><div id="no_div"> not reload </div></td>
<td><div id="some_div"> some_div </div></td>
</tr>
</table>
</body>



Last modified 13 years ago Last modified on Aug 25, 2011, 4:27:59 PM