I started to learn node.js. But I am having a problem reading the incoming data. title, content, postId does not have any trouble while reading. But I can not read "categories[]"
// NEWPOST.JADE
$("#editButton").click(function() {
var formSerialize = $("form#newPost").serialize();
$.ajax({
type: 'PUT',
url: 'auth/new-post',
data: formSerialize
}).done(function() {
console.log("SUCCESS");
}).fail(function() {
console.log("FAIL");
})
});
// POST.JS
router.put('/', upload.single('image'), function (req, res, next) {
console.log(req.body);
console.log("new selected categories: " + req.body.categories);
const promise = Post.findByIdAndUpdate(
req.body.postId,
req.body,
{
new: true
}
);
promise.then((post) => {
res.json(post);
}).catch((err) => {
res.send(500);
})
});
// RESULT CMD
{ title: 'post title',
content: '<p>post content</p>
',
'categories[]':
[ '5a7310e7cfa4c52440957bde',
'5a7310eccfa4c52440957bdf',
'5a7310f0cfa4c52440957be0',
'5a7310f5cfa4c52440957be1' ],
postId: '5a7628be95d1d63668b9da31' }
new selected categories: undefined
PUT /auth/new-post 200 209.076 ms - 2
Despite the arrival of new selected categories it seemed to undefined. how can i meet it.
Thank you in advance.