【发布时间】:2020-01-15 17:09:57
【问题描述】:
基本上,我有一个系统可以访问数据库,获取一些信息,然后访问其他一些站点,并获取一些信息。这大约需要 3 秒。我想做的是在服务器获取其余数据时显示This Page Is Loading 页面,一旦获取所有数据,我希望服务器发送目标页面。
const express = require('express');
const app = express();
app.set('view engine','ejs')
app.use(express.static('public'));
app.set('views', '/app/public/')
app.get('/', async(req, res) =>{
//Need to send `This Page Is Loading` here.
//Contact DB (takes 3 seconds)
res.send("home/index")//Send the final page.
})
我正在使用 Node.JS + Express + Ejs,所以我们可能能够在 ejs 文件中提取数据库信息并显示加载屏幕。不太确定你..
我有一个想法。
const express = require('express');
const app = express();
app.set('view engine','ejs')
app.use(express.static('public'));
app.set('views', '/app/public/')
function getdbinfo(name){
//getinfo
return info
}
app.get('/', async(req, res) =>{
res.send("home/index",{req,getdbinfo})//Send a page with get info function.
})
在 ejs 页面上,我们需要显示一个加载页面并在后台发出请求。
【问题讨论】: