Technologies: [ {Frontend: 'Vue-js 2'}, {Backend: 'Node-js / Express / SQL'} ]
I need to send a comment comming from a form-data with 3 entries (content / userID / PostId)
Front-side I have all the values setup. Then in my backend when I log req.body I got an empty Object...
Why my form data is empty ? or is my backend not able to read it ?
Function from my front :
newComment(idPost) {
const comment = new FormData();
comment.append('content', this.comment);
comment.append('userId', this.user.userId);
comment.append('postId', idPost);
for (let pairs of comment.entries()) {
console.log(pairs);
}
const headers = {
'Content-type': 'application/json',
Authorization: 'Bearer ' + this.user.token,
};
axios
.post(`${url}comment`, comment, { headers }).then(etc....)
Function from my back :
exports.createComment = (req, res, next) => {
console.log('new comment............')
console.log(req.body);
const content = req.body.content;
const userId = req.body.userId;
const postId = req.body.postId;
db.query(
`INSERT INTO comments (content, userId, postId) VALUES ('${content}', '${userId}', '${postId}')`,
(err, result, fields) => {...}