【发布时间】:2019-12-06 23:18:07
【问题描述】:
节点 JS 的新手,遇到删除请求返回 404 未找到的问题。我可以正常连接到数据库,能够通过发布请求添加到数据库中,只有删除请求才会导致问题。这是来自我的控制器文件:
app.delete('/:item', function(req,res)
{
steTodo.find({item:req.params.item.replace(/\-/g, " ")}).remove(function(err,data)
{
if(err) throw err;
res.json(data);
});
这是jquery:
$('.removeClass').on('click', function()
{
var item = $(this).text().replace(/ /g, "-");
$.ajax({
type: 'DELETE',
url: '/' + item,
success: function(data)
{
//do something with the data via front-end framework
alert('Successfully called');
location.reload();
},
error: function(jqxhr, status, exception)
{
alert('Exception:', status);
}
});
});
这是我在控制台中看到的错误:
jquery.min.js:2 DELETE http://localhost:3000/get-flowers 404 (Not Found)
任何想法或想法将不胜感激。
【问题讨论】: