注意我沒有洗牌通過很多答案,找不到一個匹配我的答案。快遞 - 不能POST /報價
試圖學習快遞和節點。在index.html中提交表單時,以下內容在瀏覽器中返回「無法POST /引用」,控制檯中沒有任何內容,但GET方法正常工作並加載頁面。
const express = require("express");
const app = express();
app.listen(3000,() => {
console.log("listening to port 3000");
});
app.get('/', (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.post('/post', (req, res) => {
console.log("Hellloooooooooo!");
});
指數
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="script.js" type="text/javascript"></script>
<title></title>
</head>
<body>
<form action="/quotes" method="POST">
<input type="text" placeholder="name" name="name">
<input type="text" placeholder="quote" name="quote">
<button type="submit">SUBMIT</button>
</form>
</body>
</html>
app.post('/後',(req,res)=> {should change to/quotes –
你沒有爲'/ quotes'定義的路由,只有'/ post'。你的客戶正在試圖發表一篇文章給'/ quotes由...定義你的表單的「動作」屬性 –