Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

node.js - Trying to activate axios.delete method from react to node JS via title name from input

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);
  }
});

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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...