H
H
Hahahah2017-10-17 18:53:36
JavaScript
Hahahah, 2017-10-17 18:53:36

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

Server
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

1 answer(s)
H
Hahahahh, 2017-10-18
@hahahahh

The error turned out to be that in the new version of Mongoose, promises need to be written manually
mongoose.Promise = global.Promise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question