无法获取POST路线

时间:2018-12-01 08:53:04

标签: node.js express mean-stack

我正在一个项目上,但是找不到以下代码中的错误。

我在以下代码中没有发现任何问题(imo),但不知何故,它没有发布请求。

我无法在此路线上接收发帖请求

错误:无法发布/ campgrounds / 5c023e5f1452761b2b937e91 / maketreasurer

router.post("/:id/adminpanel/maketreasurer",function(req,res){
    res.send("posted");
    });

我正在从此页面发送我的请求:

   <% include ../partials/header %>

//show all faculty heads
//select faculty header
//assign faculty head

<h3>Users</h3>
<table id="t01">
            <tr>
              <th>firstname</th>
              <th>----</th>
              <th>Username</th>
              <th>----</th>
              <th>Faculty Number</th>
              <th>----</th>
              <th>Student Number</th>
              <th></th>
            </tr>

<% parm.users.forEach(function(users){ %>
          <tr>
            <td><%= users.firstname %></td>
            <td></td>
            <td><%= users.username%></td>
            <td></td>
            <td><%= users.facultynumber%></td>
            <td></td>
            <td><%= users.studentnumber%></td>          
          </tr>
        <% }); %>
        </table>
        </form>

        Make A Treasurer
        <form action="/campgrounds/<%=parm.id%>/maketreasurer" 
        method="POST">
          <button>Submit</button>
        </form>

1 个答案:

答案 0 :(得分:1)

错误非常明显,

Cannot POST `/campgrounds/5c023e5f1452761b2b937e91/maketreasurer`
where id = 5c023e5f1452761b2b937e91

现在,您要路由的是/:id/adminpanel/maketreasurer,并将/campgrounds作为基本URL,adminpanel在哪里?发布请求应该是:

/campgrounds/5c023e5f1452761b2b937e91/adminpanel/maketreasurer