javascript - 这个路由这么写有什么问题?我想删掉一条记录
ringa_lee
ringa_lee 2017-04-17 16:35:04
0
2
284

我在roomview.html页面上想要删掉一条显示出来的记录,roomview.html部分代码如下:

<h1>房间列表</h1>
<p>
    <a href="/roomview/addroom">增加</a>

</p>
<table>
    <thead>
    <tr>
        <th>_id</th>
        <th>roomName</th>
        <th>roomContent</th>
        <th>roomCreateUser</th>
        <th>roomImg</th>
        <th>roomCreateDate</th>
        <th>roomJoinPeos</th>
        <th>roomChat</th>
    </tr>
    </thead>
    <tbody>
    <% rooms.forEach(function( room ){ %>
    <tr>
        <td><%= room._id%></td>
        <td><%= room.roomName %></td>
        <td><%= room.roomContent %></td>
        <td><%= room.roomCreateUser %></td>
        <td><%= room.roomImg %></td>
        <td><%= room.roomCreateDate %></td>
        <td><%= room.roomJoinPeos %></td>
        <td><%= room.roomChat %></td>
        <td><a href="/roomview/delete?id=<%=room._id%>">删除房间</a> | <a href="/roomview/modifyroom?id=<%=room._id%>">更新房间信息</a></td>
    </tr>
    <% }); %>
    </tbody>

路由roomview.js对应删除部分代码如下:

router.get("/delete/:id",function(req,res){
    console.log(req.params.id);
    Room.findById(req.params.id,function(err,doc){
        if(!doc){
            return next(new NotFound("Doc not found"))
        }else{
            doc.remove(function(){
                res.redirect("/roomview");
            })
        }
    });
});

不过当我点击删除房间后页面却显示如下:

Cannot GET /roomview/delete
ringa_lee
ringa_lee

ringa_lee

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!