我在登录页面的反应节点项目中面临以下问题。到目前为止,我在每次执行后一次又一次地检查我的代码,但仍然显示错误。我想从登录页面将数据传递到我的 mysql 数据库中。这是我申请的第一阶段。createError.js:16 Uncaught (in promise) Error: Request failed with status code 404Login.js 文件..import React from "react";import "./Login.css";import jQuery from "jquery";import { useState } from "react";import Axios from "axios";const Login = () => { const [userNameReg, setUserNameReg] = useState(""); const [emailReg, setEmailReg] = useState(""); const [passReg, setPassReg] = useState(""); const signup = () => { Axios.post("http://localhost:3000/login", { username: userNameReg, email: emailReg, password: passReg, }).then((res) => { console.log(res); }); }; return ( <div> <section className="account"> <div class="container" id="container"> <div class="form-container sign-up-container"> <form action="#"> <h1>Create Account</h1> <div class="social-container"> <a href="#" class="social"> <i class="fab fa-facebook-f"></i> </a> <a href="#" class="social"> <i class="fab fa-google-plus-g"></i> </a> <a href="#" class="social"> <i class="fab fa-linkedin-in"></i> </a> </div> <span>or use your email for registration</span> <input type="text" placeholder="Name" onChange={(e) => { setUserNameReg(e.target.value); }} /> <input type="email" placeholder="Email" onChange={(e) => { setEmailReg(e.target.value); }}
1 回答
长风秋雁
TA贡献1757条经验 获得超7个赞
你有你的app.listen帖子路由的内部......所以服务器只会在收到帖子请求时开始侦听传入连接(它不能这样做,因为它没有侦听)。将调用放在函数之外。
app.post("/login", (req, res) => {
const username = req.body.username;
const email = req.body.email;
const password = req.body.password;
db.query(
"INSERT INTO signup (name, email,password) VALUES (?,?,?)",
[username, email, password],
(err, result) => {
console.log(err);
}
);
});
app.listen(3000, () => {
console.log("Everything Okay......");
});
添加回答
举报
0/150
提交
取消