0

我第一次使用 fetch() 从 API 获取一些数据:'https://www.codewars.com/api/v1/users/thenarfer'。

我的目标是 console.log 数据。我相信数据是 JSON 格式。

我使用以下代码得到的错误是:Uncaught ReferenceError: data is not defined

POST 或 GET 是正确的方法吗?我如何从这里继续?

fetch('https://www.codewars.com/api/v1/users/thenarfer', {
    method: 'GET',
    mode: 'no-cors',
    credentials: 'include',
    body: JSON.stringify(data),
    headers: {
      'Content-Type': 'application/json'
    }
  }).then((res) => res.json())
  .then((data) => {
    console.log(data)
  })
  .catch((err) => console.log(err));

4

0 回答 0