MM們
2023-07-20 14:59:35
我在登錄頁面的反應(yīng)節(jié)點項目中面臨以下問題。到目前為止,我在每次執(zhí)行后一次又一次地檢查我的代碼,但仍然顯示錯誤。我想從登錄頁面將數(shù)據(jù)傳遞到我的 mysql 數(shù)據(jù)庫中。這是我申請的第一階段。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 回答

長風(fēng)秋雁
TA貢獻1757條經(jīng)驗 獲得超7個贊
你有你的app.listen帖子路由的內(nèi)部......所以服務(wù)器只會在收到帖子請求時開始偵聽傳入連接(它不能這樣做,因為它沒有偵聽)。將調(diào)用放在函數(shù)之外。
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
提交
取消