JavaScript-无法获取/api/list

JavaScript-无法获取/api/list,javascript,Javascript,我在一个网站上工作,在这个网站上,用户应该能够将项目发布到列表中。现在,当我尝试发布一些东西时,它会出现一个错误 Failed to load resource: the server responded with a status of 422 (Unprocessable Entity). 当在控制台中单击它时,它会打开一个新的点击,在这里它只会说 Cannot GET /api/list 同样在命令提示符中,它说 Unhandled rejection Error: Can't set

我在一个网站上工作,在这个网站上,用户应该能够将项目发布到列表中。现在,当我尝试发布一些东西时,它会出现一个错误

Failed to load resource: the server responded with a status of 422 (Unprocessable Entity).
当在控制台中单击它时,它会打开一个新的点击,在这里它只会说

Cannot GET /api/list
同样在命令提示符中,它说

Unhandled rejection Error: Can't set headers after they are sent.
有人知道为什么会这样吗?我能做些什么来修复它?以下是我的一些代码片段:

Index.HTML:

fetch('/api/list', options)
    .then(response => response.json())
    .then(response => {
          if (response.status == 'OK') {
          console.log('song is added')
          getList(items)

          } else {
          alert(response.message)
        }
    })
 }
app.post('/api/list', userIsAuthenticated, (req, res) => {
  let {
    titleArtist
    } = req.body

   let user_id = req.session.user.id

   // seaching for user id in database
   let query = {
     where: {
     userId: user_id
    }
  }
Server.js:

fetch('/api/list', options)
    .then(response => response.json())
    .then(response => {
          if (response.status == 'OK') {
          console.log('song is added')
          getList(items)

          } else {
          alert(response.message)
        }
    })
 }
app.post('/api/list', userIsAuthenticated, (req, res) => {
  let {
    titleArtist
    } = req.body

   let user_id = req.session.user.id

   // seaching for user id in database
   let query = {
     where: {
     userId: user_id
    }
  }

它也可能在代码的其他地方出错。请告诉我是否应该发布更多的代码片段。

这是因为您正在向post API发出GET请求

这就是你能做到的


无法加载资源:。。。。很可能您的scss文件中有错误,导致无法正确呈现该文件。您的
fetch
是什么样子的。header错误会准确地表示它所表示的内容,即在发送请求后添加一个header。此外,您可以显示
选项
fetch执行GET。app.post(“/api/list”不应该是app.get吗?