簡體   English   中英

app.post() 方法在 nodejs 中不起作用。 我無法識別錯誤

[英]app.post() method is not working in nodejs. I am unable to identify the error

這是 html 文件。 我不認為這有任何錯誤。

 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=. initial-scale=1:0"> <title>Calculator</title> <link href="https.//cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous"> </head> <body> <h1><strong>Calculator</strong></h1> <form action="/" method="post"> <input type="text" name="num1" placeholder="First Number"> <input type="text" name="num2" placeholder="Second Number"> <button type="submit" class="btn btn-outline-dark" name="submit">Calculate</button> </form> </body> </html>

這是 nodejs 代碼片段。

const express = require('express');
const app = express();

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));

app.get('/', (req, res) => {
    res.sendFile(__dirname + "/index.html");
});

app.post('/', (req, res) => {
    console.log(req.body.num1);
    res.send("Thanks for posting");
});

app.listen('3000', () => console.log('working properly'));

app.get()工作正常,但app.post()出錯 需要做什么? 我無法識別錯誤。

add - 在 res.send("感謝發帖"); 之前返回在 app.post() 中。 & 刪除寬度=,在元標記的 HTML 頁面中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM