Answer the question
In order to leave comments, you need to log in
Failed to load resource: the server responded with a status of 404 (Not Found)?
Error while sending data to
client server:
function submitForm(e) {
e.preventDefault();
const res = {
id: window.location.pathname.replace(/\/profile\//, ''),
images: images_of_post
};
fetch(`http://localhost:3000/profile/post/${res.id}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(res)
});
}
router.post('/post/:id', async (req, res) => {
try {
const { text, images } = req.body;
const findUser = await User.findById(req.params.id);
const newPost = new Post({
userId: findUser._id,
user: findUser,
images: images,
text,
date: new Date(),
comments: []
})
await newPost.save();
res.redirect('/');
} catch (e) {
res.status(404).json({ message: e.message });
}
})
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