1
下面我有一個用戶可以發送的發佈請求,如果名稱爲_method
的隱藏表單項目被刪除,它將向我自己的服務器發送一個請求到不同的路由並從數據庫中刪除該帖子。這個過程應該如何工作?如何讓用戶刪除帖子?
app.post("/posts/:id/delete", function(req, res){
if(req.body._method = "delete"){
request({
"method": "delete",
"url": "/posts/"+req.param.id
}, function(err, response, body){
res.redirect("/posts");
});
}
});
app.delete("/posts/:id", function(req, res){
//delete it from the database
res.redirect("/posts");
});
爲什麼不讓用戶的請求成爲HTTP DELETE的請求而不是POST然後重定向? – 2013-02-17 09:25:42
@JohnZwinck http://stackoverflow.com/a/166501 – 2013-02-17 09:55:28