Javascript 通过节点API将值从html表单传递到另一个表单(重定向页面)
我有IDForm.html和registration.html表格 如果用户在IDForm.html中输入了正确的ID,它将重定向到registration.html ID是mongodb中集合的objectID mongooseDB上的ID检查是在nodejs API上完成的Javascript 通过节点API将值从html表单传递到另一个表单(重定向页面),javascript,html,node.js,mongodb,Javascript,Html,Node.js,Mongodb,我有IDForm.html和registration.html表格 如果用户在IDForm.html中输入了正确的ID,它将重定向到registration.html ID是mongodb中集合的objectID mongooseDB上的ID检查是在nodejs API上完成的 const checkID = async (req, res ,next){ var ID = "5e9cca24beabb96a4caedc35" User.findById(ID,
const checkID = async (req, res ,next){
var ID = "5e9cca24beabb96a4caedc35"
User.findById(ID,
(err) => {
if (err) return handleError(err);
res.redirect('/api/users/'+ ID +'/register')
})
如何重定向到已加载此ID的注册页面。因此,注册中的用户可以使用此ID更新mongodb上的集合
注册是更新mongodb上现有集合的一种方式。在注册端,路由应该能够从请求URL获取参数并将其传递到前端 假设这是注册路线:
router.get('/registration,(req,res)=>{
//You will have the access to the URL parameters here
//Just an example
console.log(req.params.id)
//Pass the id to the front end if you are using a templating
// engines like express or ejs
res.render('template',{
id:req.params.id
});
//Or you can just send it out using
res.send(req.params.id)
//And handle it in the front end as you like
});
您是否收到错误消息?这在什么方面没有达到预期效果?你使用的是某种模板引擎吗?我没有使用模板引擎,index.html加载到server.js中,然后所有其他页面都从索引和一个页面重定向到另一个页面,我不知道这是正确的选择还是应该为每个页面使用res.sendfile,或者模板引擎