javascript - 对象的成员被忽略
问题描述
首先,我在网络编程方面非常糟糕,而且我有一个问题......这是我的 index.js:https ://pastebin.com/92SGEChN,我的 postBook() 函数:
function postBook() {
let bookTitle = document.getElementById("b-title").value;
let bookAuthor = document.getElementById("b-author").value;
let bookDesc = document.getElementById("b-descript").value;
const book = {
title: bookTitle,
author: bookAuthor,
description: bookDesc
};
/// il postez
fetch('/books', {
method: 'post',
headers: {
"Content-type": "application/json"
},
body: JSON.stringify(book)
}).then(function() {
getBooks();
});
}
这是我的 script.js:https ://pastebin.com/S7e2vYrc 。
app.post("/books", (req, res) => {
const booksList = readJSONFile();
var newId = uuidv1();
var newBook =
{
title: req.body.title,
author: req.body.author,
description: req.body.description,
id: newId
};
booksList.push(newBook);
writeJSONFile(booksList);
res.send(booksList);
});
似乎从未见过 book 对象的“作者”成员,并且它没有出现在 db.json 中。为什么,我该如何解决这个问题?
解决方案
推荐阅读
- linux - cPanel 安装问题
- vue.js - 禁用规则时,vue-cli linting 抛出驼峰警告
- visual-c++ - 如何“正确关闭 MFC 无模式对话框并修复资源泄漏”
- java - 授权不起作用(Spring Security)
- node.js - 如何使用 node.js 和 react.js 下载大型 CSV 文件
- java - notifyItemInsertedRange() 不适用于 recyclerview 适配器
- android - 使用 React Native 和 Expo 实现闹钟(iOS 和 Android)
- jpa - 获取 Bean Validation 错误并向用户显示相应消息的正确方法
- javascript - 如何在命令中设置 process.env 变量并在 webpack 文件中检索
- python - 测试字符串列表中的单个连续字符串