2017-02-22 2 views
0

注記多くの回答をシャッフルしましたが、私のものと一致するものは見つかりませんでした。Express - POST /引用符を使用できない

エクスプレスとノードを学ぼうとしています。 index.htmlにフォームを送信すると、ブラウザでは「Can not POST/quotes」が返され、コンソールでは何も返されませんが、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> 
+0

app.post( '/ポスト'/ quotes 'に変更する必要があります。 –

+0

'/quotes'のためのexpressで定義されたルートはありません、 '/ post'のみです。クライアントは'/quotesへの投稿をしようとしています'あなたのフォームの 'action'属性 –

答えて

1

、あなただけの2つのルートがあり、唯一つのポスト/postルートが、ノーポスト/quotesルート

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!"); 
}); 

// just make a simple quotes route 

app.post('/quotes', (req, res) => { 
    console.log("hello from quotes route!"); 
}); 
+0

それはそうです!ありがとう! – jylny

+0

それをマークすることで回答を受け入れます。他人にも役立ちます –

+0

時間制限を待っていました^。^ – jylny

関連する問題