我的查询在我的index.js文件中运行,该文件从最后两分钟加载最新消息,然后通过数据数组将数据放入ejs文件中。
<script src="<?php echo base_url() ?>plugins/jquery-datatable/jquery.dataTables.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/skin/bootstrap/js/dataTables.bootstrap.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/dataTables.buttons.min.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/buttons.flash.min.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/jszip.min.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/pdfmake.min.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/vfs_fonts.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/buttons.html5.min.js"></script>
<script src="<?php echo base_url() ?>plugins/jquery-datatable/extensions/export/buttons.print.min.js"></script>
但是我想用仪表板上的任何更新来刷新ejs页面(这样消息看起来就像是实时馈送一样),它不一定是最后两分钟。知道怎么做到这一点?
这是我的ejs文件:
client.connect();
const query = client.query(new Query(`SELECT * FROM my_table WHERE unix_timestamp > (${(Date.now()/1000) - 1800})`))
var data = [];
var total = 0;
query.on('row', (row) => {
console.log(row);
total += 1;
data.push(row);
})
query.on('end', (res) => {
console.log("this is the end");
console.log("total is:", total);
})
router.get('/', (req, res) => {
res.render('index', {
data: data
});
});