首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Express -无法发布/quotes

Express -无法发布/quotes
EN

Stack Overflow用户
提问于 2017-02-22 23:43:05
回答 1查看 680关注 0票数 0

请注意,我确实洗了很多答案,找不到一个与我匹配的答案。

尝试学习express和node。在index.html中提交表单时,在浏览器中返回"Cannot POST /quotes“,在控制台中什么也不返回,但是GET方法可以正常工作并加载页面。

代码语言:javascript
复制
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!");
});

索引

代码语言:javascript
复制
<!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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-22 23:47:19

没有报价路由,您只有2个路由,并且只有一个post /post路由,但没有post /quotes路由

代码语言:javascript
复制
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!");
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42396025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档