我正在尝试检查用户是否已经存在于数据库中。我正在使用javascript函数从客户端发送用户的电子邮件ID到节点js路由。路由应查找数据库中是否存在用户。但是所有结果都为空。/* this is the route*/router.route('/checkUserInDatabase:email').get(async(req,res)=>{const user = await User.findOne({ 'email': req.params.email });console.log(user);});/* this is the client side function*/function checkifEmailExists(x){ $.get('/users/checkUserInDatabase:'+ x , function(data, status){ if(data=='true'){ alert('email exists'); } if(data=='false'){ alert('email does not exist'); } });}
2 回答

慕婉清6462132
TA贡献1804条经验 获得超2个赞
问题出在您不应该:
在客户端使用的路由中,应该是
'/users/checkUserInDatabase/'+ x
和服务器端应该是
'/checkUserInDatabase/:email'
添加回答
举报
0/150
提交
取消