Muhammad Yasir Javed
Muhammad Yasir Javed

Reputation: 97

Cannot Get POST Route

I am working on a project but unable to find the bug i have made in the following code.

I dont find any issues (imo) in the following code but somehow it's not posting requests.

Im unable to receive post requests on this route:

Error: Cannot POST /campgrounds/5c023e5f1452761b2b937e91/maketreasurer

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

Im sending my request from this page:

   <% 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>

Upvotes: 0

Views: 128

Answers (1)

Aritra Chakraborty
Aritra Chakraborty

Reputation: 12542

The error is pretty obvious,

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

Now, you're route is /:id/adminpanel/maketreasurer considering /campgrounds as base url, where is adminpanel? The post request should have been:

/campgrounds/5c023e5f1452761b2b937e91/adminpanel/maketreasurer

Upvotes: 1

Related Questions