php 页面
<?php
header ( 'content-type:text/html;charset=utf-8' );
$mysqli = new mysqli ( 'localhost', 'root', '', 'java' );
if ($mysqli->connect_errno) {
die ( 'CONNECT ERROR:' . $mysqli->connect_error );
}
$mysqli->set_charset ( 'utf8' );
$sql = "select kd,sum from kd";
$mysqli_result = $mysqli->query ( $sql );
$rows = array ();
while ( $row = $mysqli_result->fetch_assoc () ) {
$rows [] = $row;
}
echo json_encode ( $rows );
html 页面
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>刷新</title>
<link rel="stylesheet" href="./kb.css" type="text/css" />
<script src="jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
updateMsg();
});
function updateMsg() {
$.post("getData.php", {
}, function(json) {
var arr=eval(json);
var tr=null;
for(var i=0;i<arr.length;i++){
tr+="<tr>"+
"<td>"+arr[i].kd+"</td>"+
"<td>"+arr[i].sum+"</td>"+
"</tr>";
}
$("#datatotable").html(tr);
setTimeout('updateMsg()', 60000);
});
}
</script>
</head>
<body>
<div id="main">
<table id="datatotable">
</table>
</div>
</body>
</html>