很奇葩的跳转问题。。。
发布于 10 年前 作者 CarlosRen 3220 次浏览 最后一次编辑是 8 年前
app.del('/:id',function(req,res){
	User.findById(req.params.id,function(err,doc){
		if(!doc){
			return next(new NotFound('document is not found'))
		}
		doc.remove(function(){
			res.redirect('/listuser');
		});
	})
});
<% for(var i=0; i<doc.length; i++) { %>
        <li>
        <%= doc[i].id %>
        <%= doc[i].username %>
        <%= doc[i].password %>
        <form method='post' ,action='/<%= doc[i].id %>'>
           <input type="submit" value="del" />
        </form>
        </li>
    <% } %>

Cannot POST /listuser ejs 为啥啊? app.post也不行。。。

3 回复

有启用method-override模块吗? 如果没有, 启用该模块,再加个 <input type="hidden" value="DELETE" name="_method">

可以删除了 不过没有执行跳转 显示Moved Temporarily. Redirecting to /listuser

<form method=‘post’ ,action=’/<%= doc[i].id%>/userdel’> app.del(’/:id/userdel’,function(req,res){ 这样则显示Cannot DELETE /listuser

回到顶部