经常更新mysql结果节点js

时间:2015-12-25 11:30:45

标签: mysql node.js

我正在开发一个Web应用程序,我正在使用节点js和mysql。我还在学习节点js。我试图在js文件中使用mysql执行查询并且它有效。但是它只在我刷新页面时才有效。我希望它在每个持续时间更新查询结果,而不是在我刷新页面时。我怎样才能做到这一点?非常感谢你!

这是我的js文件中的代码

var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var async = require('async');

var pool = mysql.createPool({
connectionLimit : 10,
host            : 'localhost',
user            : 'root',
password        : 'AK94',
database          : 'aubookit'
});


/* GET home page. */
router.get('/', function (req, res, next) {
pool.getConnection(function (err, connection) {
    async.parallel([
        function (callback) { connection.query('select * from Librarians', callback) },
        function (callback) { connection.query('select * from Students', callback) },
        function (callback) { connection.query('select * from reservations', callback) }
    ], function (err, results) {

        res.render('index', { title: 'BookIT', Librarians: results[0][0], Students: results[1][0]});
        connection.release();
    });
});
});


router.get('/LibrarianPage', function (req, res, next) {
res.render('librarian', { title: 'Librarian Page' });
});

router.get('/StudentPage', function (req, res, next) {
    pool.getConnection(function (err, connection) {
        async.parallel([
            function (callback) { connection.query('select * from reservations', callback) }
    ], function (err, results) {

        res.render('student', { title: 'Student Page', reservations: results[0][0] });
        connection.release();
    });
});

});

module.exports = router;

router.get('/LibrarianPage', function (req, res, next) {
    res.render('librarian', { title: 'Librarian Page' });
});

router.get('/StudentPage', function (req, res, next) {
    res.render('student', { title: 'Student Page' });
});

module.exports = router;

0 个答案:

没有答案