Answer the question
In order to leave comments, you need to log in
Why is axios post not working?
There are two requests, get and post, respectively, the get request can take data from the db by URL, but the post request for some reason does not send them and the pending status constantly hangs. I use React Express and MongoDB.
Customer
axios.get('/newspost').then(res => {this.setState({news: res.data})})
axios.post('/newspost', item).then(res => console.log(res)).catch(err => console.log(err))
app.get('/newspost', (req, res) => {
db.allNews().then(data => res.send(data));
});
app.post('/newspost', (req, res) => {
db.createNews(req.body).then(data => res.send(data));
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question