<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script src="vendor/jquery-1.7.2.min.js"></script>
<script src="jquery.dynatable.js"></script>
<link rel="stylesheet" href="jquery.dynatable.css" >
</head>
<body>
<script>
$(document).ready(function() {
var mytable= $("#dynatable");
setInterval(function() {
$.ajax({
url: "do.php",
success: function(data) {
myRecords = $.parseJSON(data);
mytable.dynatable({
dataset: {
records:myRecords
}
});
mytable.data('dynatable').settings.dataset.records=myRecords;
mytable.data('dynatable').dom.update();
console.log(data);
}
});
}, 1000);
});
</script>
<table id="dynatable">
<thead>
<th>test1</th>
<th>test2</th>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
服务端php代码
<?php
$response = array();
$response [] = array(
"test1" => "AAAA".time(),
"test2" => "BBBB".time()
);
echo json_encode($response);
?>
$(document).ready(function() {
setInterval(function() {
$.ajax({
url: "myStuff.php",
success: function(data) {
console.log(data);
var myRecords = $.parseJSON(data);
var dynatable = $('#dynatable').dynatable({
dataset: {
records: myRecords
}
}).data('dynatable');
dynatable.settings.dataset.originalRecords = myRecords;
dynatable.process();
}
});
}, 3000);
});