第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

運(yùn)行節(jié)點(diǎn)服務(wù)器時(shí)出現(xiàn) 404

運(yùn)行節(jié)點(diǎn)服務(wù)器時(shí)出現(xiàn) 404

哈士奇WWW 2022-01-07 10:23:56
嗨學(xué)習(xí)使用節(jié)點(diǎn)和其他后端組件并在運(yùn)行一個(gè)簡(jiǎn)單的輸入表單時(shí)遇到這個(gè) 404:Not Found404NotFoundError: Not Found    at /Users/samgniel/Desktop/saas-tutorial/app.js:25:8    at Layer.handle [as handle_request] (/Users/samgniel/Desktop/saas- tutorial/node_modules/express/lib/router/layer.js:95:5)    at trim_prefix (/Users/samgniel/Desktop/saas- tutorial/node_modules/express/lib/router/index.js:317:13)    at /Users/samgniel/Desktop/saas-tutorial/node_modules/express/lib/router/index.js:284:7    at Function.process_params (/Users/samgniel/Desktop/saas- tutorial/node_modules/express/lib/router/index.js:335:12)    at next (/Users/samgniel/Desktop/saas- tutorial/node_modules/express/lib/router/index.js:275:10)    at SendStream.error (/Users/samgniel/Desktop/saas-tutorial/node_modules/serve- static/index.js:121:7)    at SendStream.emit (events.js:210:5)    at SendStream.error (/Users/samgniel/Desktop/saas- tutorial/node_modules/send/index.js:270:17)    at SendStream.onStatError (/Users/samgniel/Desktop/saas- tutorial/node_modules/send/index.js:421:12)輸入表單的代碼是:<form action="/signup" method="post">  <input required type="email" name="email" id="emailForm" placeholder="Your Email">  <input type="password" name="password" id="passwordForm" placeholder="Password">  <input type="submit" name="" id="" value="Signup!"></form>.js 調(diào)用函數(shù)是:app.post('/signup', function(req, res, next) {console.log(req.body);});幫助解決此錯(cuò)誤將不勝感激:)
查看完整描述

2 回答

?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

抱歉耽擱了...我試圖在代碼沙箱上托管它...


你可以像這樣制作你的節(jié)點(diǎn)端


const express = require("express");

const bodyParser = require("body-parser");

const cors = require("cors");

const path = require("path");


const app = express();

const router = express.Router();

const PORT = process.env.PORT || 5000;


app.use(cors());

app.use(bodyParser.urlencoded({ extended: false }));

app.use(bodyParser.json());


router.get("/", function(req, res) {

  res.sendFile(path.join(__dirname + "/index.html"));

});


router.post("/signup", (req, res) => {

  console.log(req.body);

});


app.use(router);


app.listen(PORT, () => {

  console.log(`Server started at PORT:${PORT}`);

});

并創(chuàng)建一個(gè) HTML 文件,您將在其中使用 fetch API 使用 API


像這樣的東西


<!DOCTYPE html>

<html>

  <head>

    <meta charset="UTF-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <meta http-equiv="X-UA-Compatible" content="ie=edge" />

    <title>Document</title>

  </head>

  <body>

    <form action="/signup" method="post">

      <input

        required

        type="email"

        name="email"

        id="emailForm"

        placeholder="Your Email"

      />

      <input

        type="password"

        name="password"

        id="passwordForm"

        placeholder="Password"

      />

      <input type="submit" name="" id="submit" value="Signup!" />

    </form>


    <script>

      const emailForm = document.querySelector('#emailForm');

      const passwordForm = document.querySelector('#passwordForm');

      const submit = document.querySelector('#submit');


      const submitFetch = (url, data) => {

        fetch(url, {

          method: 'POST',

          mode: 'cors',

          cache: 'no-cache',

          credentials: 'same-origin',

          headers: {

            'Content-Type': 'application/json'

          },

          redirect: 'follow',

          referrer: 'no-referrer',

          body: JSON.stringify(data)

        }).then(response => response.json());

      };


      submit.addEventListener('click', e => {

        e.preventDefault();

        const data = {

          email: emailForm.value,

          password: emailForm.value

        };

        submitFetch('http://localhost:5000/signup', data);

      });

    </script>

  </body>

</html>

如果您想現(xiàn)場(chǎng)觀看...我將其托管在代碼沙箱上


https://codesandbox.io/s/lucid-cannon-x1wu1


查看完整回答
反對(duì) 回復(fù) 2022-01-07
?
天涯盡頭無(wú)女友

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊

您似乎沒(méi)有向客戶(hù)返回任何響應(yīng)。您可以糾正的一種方法是使用 express 提供的 res 對(duì)象中的 send 函數(shù)。


app.post('/signup', function(req, res, next) {

    console.log(req.body);

    res.send('Hello World') // this can also take an object as response. res.send({ msg: 'hello world' })

});

重新調(diào)整這條線也可能會(huì)有所幫助 ok comment out this line app.use(function(req, res, next) { next(createError(404)); });


希望這可以幫助。


查看完整回答
反對(duì) 回復(fù) 2022-01-07
  • 2 回答
  • 0 關(guān)注
  • 252 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)