javascript - 使用 Node.js 提供动态内容并在一段时间后更新
问题描述
基本上我正在搜索一段时间后更新网站上的数据。就像,在 10 秒后更改 DOM 上的工作。
我是节点新手,所以我不知道如何制作它。
我想通过 JavaScript 向服务器发出请求,但我不确定这是正确的方法。
这是我已经制作的,但我不知道我不能重新渲染所有代码。
如您所见,我使用 express 作为我的服务器。
app.get('/proof/screen', (req, res) => {
var selected = {};
function instance() {
do {
selected = orders_[Math.floor(Math.random() * orders_.length)];
} while(!selected || selected.financial_status !== 'paid' || !selected.shipping_address);
res.render('proofscreen', {
name: selected.shipping_address.first_name,
state: selected.shipping_address.city,
province: selected.shipping_address.province,
country: selected.shipping_address.country,
product: selected.line_items[Math.floor(Math.random() * selected.line_items.length)].title,
product_link: '#'
});
setTimeout(instance, Math.random() * 5000);
}
instance();
});
所以,这段代码没有做任何事情,它只是显示错误:你不能再次发送标题。
解决方案
推荐阅读
- android - 第二次打开时,BottomSheetDialogFragment 崩溃
- python - Flask Request 传递 pandas to_json 与 curl 或 Postman
- sql-server - 跨多个表列设置唯一约束
- objective-c - 超类的init方法为NS_UNAVAILABLE时如何初始化子类
- scheduled-tasks - 我的脚本是否作为计划任务运行?
- html - 无法使用 VBA 在 HTML 页面上单击导出按钮
- redux - Redux 商店的最佳规范化设计是什么?
- reactjs - 列表
尝试上传时为空 - powershell - 如何修复在 Powershell 脚本中找不到具有标识的对象
- javascript - 用于 React NextJS 的映射对象 JSX 内的 onClick 不起作用