Answer the question
In order to leave comments, you need to log in
Why does an empty object come from the front to the back?
The last question was deleted by the moderator (probably for the screenshots of the code)
Why does an empty object arrive from the front to the back?
Hello everyone, when sending a request from the front to the back, an empty object arrives in req.body on the back. I would like to find out why. Here is the code of what I send from the front:
const postNewTask = async (data) => {
const res = await fetch(API_URL + "/reminds", {
method: "POST",
body: JSON.stringify(data)
});
return res;
};
{name: "123", text: "123", taskId: "Программирование"}
const RemindsTasks = sequelize.define("reminds", {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING, unique: true, allowNull: false },
text: { type: DataTypes.STRING, unique: true, allowNull: false },
typeId: { type: DataTypes.STRING, unique: true, allowNull: true },
});
class RemindsController {
async create(req, res) {
const { name , text , typeId } = req.body;
console.log('req body',req.body)
console.log(req.body)
const remindsItem = await RemindsTasks.create({ name , text ,typeId });
return res.json(remindsItem);
}
async getAll(req, res) {
const reminds = await RemindsTasks.findAll();
return res.json(reminds);
}
}
app.use(express.json());
there is, if sent via postman everything works. 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