首页 > 解决方案 > 对象的成员被忽略

问题描述

首先,我在网络编程方面非常糟糕,而且我有一个问题......这是我的 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 中。为什么,我该如何解决这个问题?

标签: javascriptjson

解决方案


推荐阅读