当我将数据提交到数据库表时,我在浏览器控制台中遇到此错误:未捕获(承诺)错误:

我在登录页面的反应节点项目中面临以下问题。到目前为止,我在每次执行后一次又一次地检查我的代码,但仍然显示错误。我想从登录页面将数据传递到我的 mysql 数据库中。这是我申请的第一阶段。


createError.js:16 Uncaught (in promise) Error: Request failed with status code 404

Login.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);

                }}


MM们
浏览 118回答 1
1回答

长风秋雁

你有你的app.listen帖子路由的内部......所以服务器只会在收到帖子请求时开始侦听传入连接(它不能这样做,因为它没有侦听)。将调用放在函数之外。app.post("/login", (req, res) => {&nbsp; const username = req.body.username;&nbsp; const email = req.body.email;&nbsp; const password = req.body.password;&nbsp; db.query(&nbsp; &nbsp; "INSERT INTO signup (name, email,password) VALUES (?,?,?)",&nbsp; &nbsp; [username, email, password],&nbsp; &nbsp; (err, result) => {&nbsp; &nbsp; &nbsp; console.log(err);&nbsp; &nbsp; }&nbsp; );});app.listen(3000, () => {&nbsp; &nbsp; console.log("Everything Okay......");&nbsp; });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript