简体   繁体   English

Express,Node,MongoDB,EJS-删除路由器并返回304

[英]Express, Node, MongoDB, EJS - Delete router getting 304 back

I have been struggling with this for awhile and just cant get it figured out. 我已经为此苦苦挣扎了一段时间,只是无法弄清楚。 My delete button is sending the server a GET /delete? 我的删除按钮正在向服务器发送GET /删除? and returning a 304 然后返回304

This is also my first post here and i di try and figure this out for a few hours first... but i am new to programming in general and would appreciate any guides or help you can offer - thanks! 这也是我在这里的第一篇文章,我尝试先花几个小时弄清楚这个问题……但是我对编程总体还是陌生的,不胜感激您可以提供的任何指南或帮助-谢谢!

I have 3 files at play here: addpost.js, addpost.ejs, and app.js 我在这里有3个文件在播放:addpost.js,addpost.ejs和app.js

This is in addpost.js 这在addpost.js中

 router.delete('/delete', function (req, res){ Comment.findById(req._id, function (err, Comment){ console.log('DELETE removing ID: ' + comments._id) res.format({ html: function(){ res.redirect('/'); }, json: function(){ res.json({message: 'deleted', title : comments}); } }); }); }); 

This is in app.js 这在app.js中

app.use('/delete', addpost)

This is in addpost.ejs 这在addpost.ejs中

  <div class ="form">
    <form method="delete" action="/delete">
      <div class="delete">
        <button class="btn btn-raised btn-warning" type="submit">Delete</Button>
    </form>
  </div>

If the form is sending the GET request, then it probably means it doesnt support DELETE method. 如果表单正在发送GET请求,则可能意味着它不支持DELETE方法。 I think its supported since html5, but ... maybe it has partial support. 我认为它自html5以来就受到支持,但是...也许它有部分支持。 Use POST instead. 请改用POST。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM