Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to delete a listing from my mongoDB collection via mongoose react and axios , i've managed to make it work one time but somehow i messed it up and couldent figure out why , thanks for the help!

React Function

const handleDeleteProperty = async () => {

 let title = document.getElementById('title').value

  try{
      const res = await axios.delete('/delete', title);
      if(res.data.success){
          alert(res.data.msg);
      }
  }
  catch(err){
      console.error(err);
  }
}
 

React function evoking

  <button onClick={handleDeleteProperty}>DELETE LISTING</button>

Backend(List is my mongoose schema)

app.get("/delete", (req, res) => {
 
});

app.delete('/delete', async (req, res) => {
  
  try{
      await List.findOneAndRemove(req.body.title);
      return res.status(200).json({ success: true, msg: 'Product Deleted' });
  }
  catch(err){
      console.error(err);
  }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
321 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...