下面的脚本是我正在开发的一个实时问题审核系统。有人可以给我一个提示,让下面的脚本自动刷新查询和结果,可以每30秒刷新一次。也许是Ajax中的一些解决方案?
<?php
global $wpdb;
if (!empty($_POST)) {
$wpdb->query($wpdb->prepare("UPDATE wp_modera SET answered = \'Yes\' WHERE id=\'" . $_POST[\'id\']. "\'" ));
}
?>
<script>
jQuery(document).ready(function($){
$("#form1").on("change", "input:checkbox", function(){
$("#form1").submit();
});
setInterval(function(){
$.get(\'#form1\', function(data){
//$("#form1").html(data).find(\'#form1\');
});
},3000);
});
</script>
<style>
table {width: 100%;}
table tr td {border-bottom: 1px solid #666; padding: 20px 0;}
table tr td:first-child {padding-right: 20px;}
table tr td .title {color: #315AA9;}
</style>
<form id="form1" method="post" action="http://example.com/test/" >
<table>
<?php
global $wpdb;
$results = $wpdb->get_results( \'SELECT id, time, city, state, question, name FROM wp_modera WHERE release = "Yes" AND flag2 <> "PLT" AND answered = "No" ORDER BY time DESC\', OBJECT );
foreach($results as $result){
echo "<tr>";
$phpdate = strtotime($result->time );
$mysqldate = date( \'H:i:s\', $phpdate );
echo "<td><strong class=\'title\'>" . $mysqldate . " - " . $result->name . " - " . $result->city . " / " . $result->state . \'</strong><br><br> <strong>Question: </strong>\' . $result->question . "</td>";
echo "<td><input type=\'checkbox\' name=\'id\' value=\'" . $result->id . "\' /></td>";
echo "</tr>";
}
?>
</table>
</form>