后端getdata.php代码如下:<?php
include('./conn/conn.php');
$query= "select id,content,pubtime,imgsrc,thumbsrc from messages order by id desc"; $result=mysql_query($query); while( $row = mysql_fetch_array( $result ) ) { $json[] = $row; } echo json_encode($json); exit;
?>前端我想这么显示:<div class='message' id='message'>第 $id 位用户: <span>$content</span><p><a href='./$imgsrc' title='点击查看原图'><img src='./$thumbsrc'></a></p><br>$pubtime</div>前端javascript代码:
<script type="text/javascript"> function get_data() { $.ajax({ url: 'getdata.php', datatype:'json', success: function(data) { var data = eval("(" + data + ")");
... //然后这个地方应该怎么写
}
}
}
});
}
setInterval("get_data()",3000);
</script>
{{pubtime}}