node.js - 密码发布无法在 Nodejs 服务器上使用 Reactjs

标签 node.js reactjs express

我正在尝试从 Reactjs 前端将名称和密码发送到 Nodejs 服务器(使用 Expressjs)。当我发送名称和密码时,仅发送名称。这是我的 Reactjs 代码:

onSubmitSignIn = () => {
    console.log(this.state.signInPassword);
    fetch('http://localhost:3000/signin', {
        method: 'post',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify({
            name: this.state.signinName,
            password: this.state.signinPassword
        })
    })
    .then(response => response.json())
    .then(user => {
        if(user.id){
            this.props.loadUser(user);
            this.props.onRouteChange('home');
        }
    })
}

该函数正确触发,console.log() 显示密码。
这是我的 Nodejs 代码:

 app.post('/signin', (req, res) => {
     const { name, password } = req.body;

     console.log("FRONT END : ", password);
     console.log("BACK END: ", database[0].password);
     console.log("FRONT END : ", name);
     if(name == database[0].name && password == database[0].password){
         res.json(database[0]);
     }else{
         res.status(400).json("Couldn't get user");
         console.log('didnt work');
     }
 })

显示我从前端发布的名称的console.log(),但不显示我从前端发布的密码的console.log()。为什么会出现这种情况?

最佳答案

不知道这是否是一个拼写错误,但在控制台日志中您使用的是驼峰式大小写:

console.log(this.state.signInPassword);

在正文中你错过了 I 大写:

password: this.state.signinPassword

关于node.js - 密码发布无法在 Nodejs 服务器上使用 Reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50226055/

相关文章:

javascript - node.js watchFile() 不观看

javascript - 如何检查 NodeJS 中的端口是否繁忙?

reactjs - !important 在 React Native 中的使用

reactjs - "Actions must be plain objects. Use custom middleware for async actions."与 react /还原

linux - 使用 libusb 而不是 hidraw 编译 hidapi

javascript - 在 nodejs 和浏览器中使用 console.log 在性能方面的成本是多少?

reactjs - store.dispatch 无法读取未定义的属性 'then'

node.js - ExpressJS : normalizePort function is really necessary?

node.js - expressJs 标题变量声明的默认值

angularjs - Node Express 不是重定向,而是返回一个字符串