PUT 404 (Not Found)



我正在尝试从表单编辑我的数据库(存储在本地主机的json服务器上(的内容。我是React和Axios的新手,所以如果我在这里大吵大闹,你可以随意侮辱我,但我仍然希望你能帮助我摆脱错误。

代码如下:

形式:

<Form onSubmit={submitPresentationEdit} id="presentationEditFormId">
<Form.Row>
<Form.Group>
<Form.Label>Title</Form.Label>
<Form.Control
name="title"
autoComplete="off"
as="textarea"
rows={1} />
</Form.Group>
<Form.Group>
<Form.Label>Subtitle</Form.Label>
<Form.Control
name="subtitle"
autoComplete="off"
as="textarea"
rows={1} />
</Form.Group>
</Form.Row>
<Form.Group>
<Form.Label>Description</Form.Label>
<Form.Control
name="description"
autoComplete="off"
as="textarea"
rows={5} />
</Form.Group>
<Button
variant="success"
type="submit"
size="sm" >
Submit
</Button>
</Form>

提交功能(submitPresentationEdit(:

const submitPresentationEdit = (event) => {
event.preventDefault();
putPresentation(event.target.title.value, event.target.subtitle.value, event.target.description.value);
}

带axios的putPresentation函数:

const putPresentation = async (tit, subtit, descr) => {
const response = await axios
.put('http://localhost:3005/presentation',
{
title: tit,
subtitle: subtit,
description: descr
},
{
headers: {
'Content-Type': 'application/json',
}
})
.then(response => {
console.log(response.data);
})
.catch((err) => {
console.log('Err', err);
});
}

这是我的json文件:

[
{
"title": "PRESENTATION",
"subtitle": "An Awesome Web delevoper on planet",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat enim arcu, eget tempor nibh congue a. Maecenas faucibus sagittis nibh, in bibendum ex. Donec eu ornare augue, nec cursus arcu. Vivamus accumsan mauris nec nulla bibendum, et eleifend nisl tristique. Pellentesque fringilla lorem id nibh auctor sagittis. Suspendisse non nisl at velit malesuada bibendum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat enim arcu, eget tempor nibh congue a. Maecenas faucibus sagittis nibh, in bibendum ex. Donec eu ornare augue, nec cursus arcu. Vivamus accumsan mauris nec nulla bibendum, et eleifend nisl tristique. Pellentesque fringilla lorem id nibh auctor sagittis. Suspendisse non nisl at velit malesuada bibendum.",
"image": "../../public/assets/images/dp.jpg"
}
]

我在控制台上得到的错误如下:

PUT http://localhost:3005/presentation 404 (Not Found)
Err Error: Request failed with status code 404
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:62)

有人知道我能做些什么来得到我需要的结果吗?提前谢谢。

我只需添加一个";id";字段中的";演示文稿";部分,所以现在:

我的json文件如下:

[
{
"id": 0,
"title": "PRESENTATION",
"subtitle": "An Awesome Web delevoper on planet",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat enim arcu, eget tempor nibh congue a. Maecenas faucibus sagittis nibh, in bibendum ex. Donec eu ornare augue, nec cursus arcu. Vivamus accumsan mauris nec nulla bibendum, et eleifend nisl tristique. Pellentesque fringilla lorem id nibh auctor sagittis. Suspendisse non nisl at velit malesuada bibendum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat enim arcu, eget tempor nibh congue a. Maecenas faucibus sagittis nibh, in bibendum ex. Donec eu ornare augue, nec cursus arcu. Vivamus accumsan mauris nec nulla bibendum, et eleifend nisl tristique. Pellentesque fringilla lorem id nibh auctor sagittis. Suspendisse non nisl at velit malesuada bibendum.",
"image": "../../public/assets/images/dp.jpg"
}
]

相关内容

  • 没有找到相关文章

最新更新