简体   繁体   中英

React.js, Node.js : send axios request in React

I try to send a request with an email and a password with axios in react.` React app:

      console.log(`
    --SUBMITTING--
    First Name: ${this.state.firstName}
    Last Name: ${this.state.lastName}
    Email: ${this.state.email}
    Password: ${this.state.password}
  `);
  this.sendData(this.state.email, this.state.password);
  // this.changeRoot("calendar");
} else {
  console.error("FORM INVALID - DISPLAY ERROR MESSAGE");
}

};

  sendData(login, password) {
console.log("login -> " + login);
console.log("passwor -> " + password);
axios.post('http://localhost:9000/signup', { email: login, psswd: password })
.then((rep) => { console.log(rep) })
.catch((error) => { console.log(error) });

}

The data in login and password are OK. Node server :

app.post('/signup', (req, res, next) => {
console.log("login -> " + req.body.email);
console.log("psswd -> " + req.body.psswd);

});

So thank for all help.

Just guessing, but, it looks like you are not configuring the bodyParser() middleware (the one that parses data from the HTTP request into the req.body )

Please see this related answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM