通过Strapi admin,我创建了一个名为"Events“的内容类型,并创建了一些条目。这些条目是我在strapi admin中创建的,它们被完美地保存并提交到后端sqlite数据库中。
但是,当我通过我的程序提出一个帖子请求时,条目会被保存,但是数据不会被保存。或者,即使我通过postman发出了一个post请求,条目也会被保存,但是数据不会保存在新条目中。
我的javascript程序如下:
const axios = require('axios')
const URL ='http://localhost:1337/api/events'
const obj = {
data : {
attributes: {
name: 'test',
venue : 'town hall',
address : 'test',
date : '2022-11-20',
time : '10 pm',
performers : 'test',
description : 'test from js programme',
user : 'test'
}
}
}
axios({
method: 'post',
url: URL,
data: obj
}).then((res)=>console.log(res.data)).
catch ((err)=> console.log(err.message))
/* response received is as under with
status code 200 on strapi server side
{
data: {
id: 57,
attributes: {
name: null,
slug: null,
venue: null,
address: null,
date: null,
time: null,
performers: null,
description: null,
createdAt: '2022-11-10T13:24:26.335Z',
updatedAt: '2022-11-10T13:24:26.335Z',
publishedAt: '2022-11-10T13:24:26.332Z'
}
},
meta: {}
}
*/
我的邮递员请求的屏幕截图如下:
令人惊讶的是,后端控制台显示响应代码200。该条目被保存,但数据未以内容类型保存。。
内容类型"Events“的所有CRUD权限都是公共的。我不知道我在这里做了什么错事。
社区,请帮助我,在我的学习。
发布于 2022-11-12 04:54:48
你也许应该
const obj = {
data : {
attributes: {
name: 'test',
venue : 'town hall',
address : 'test',
date : '2022-11-20',
time : '10 pm',
performers : 'test',
description : 'test from js programme',
user : 'test'
}
}
}
至
const obj = {
data : {
name: 'test',
venue : 'town hall',
address : 'test',
date : '2022-11-20',
time : '10 pm',
performers : 'test',
description : 'test from js programme',
user : 'test'
}
}
在post请求中,不需要将数据放在attributes
键中。
https://stackoverflow.com/questions/74390425
复制相似问题