0

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? and returning a 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

This is in 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.use('/delete', addpost)

This is in 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>

1 Answers1

0

If the form is sending the GET request, then it probably means it doesnt support DELETE method. I think its supported since html5, but ... maybe it has partial support. Use POST instead.

Rainer Plumer
  • 3,693
  • 2
  • 24
  • 42
  • Thanks for the response - i have been looking into method-override to get it do delete the associated _id value - will see how it goes – Cameron Johnston Feb 05 '16 at 17:24