小编alc*_*cia的帖子

在 Safari 11.1 中获取 - 使用控制台日志请求不起作用(不支持 ReadableStream 上传)

上次更新 Safari 浏览器(更新至 11.1)后,我注意到我的获取代码停止工作。

代码:

const options = {
  method: 'POST',
  credentials: 'include',
  body: '{"id":"xxx","note":"yyy"}',
  headers: {}
};


options.headers = new window.Headers();
options.headers.append('Content-Type', 'application/json; charset=utf-8');

function getRequest() {
  return new window.Request('https://jsonplaceholder.typicode.com/posts', options);
}

const newRe = getRequest();

console.log(newRe);

fetch(newRe)
  .then((response) => {
    return response.json();
  })
  .then((jsonObject) => {
  console.log(jsonObject)
    document.write(`ID ${jsonObject.id} was created!`);
  })
  .catch((error) => {
    document.write(error);
  });
Run Code Online (Sandbox Code Playgroud)

Codepen 上:https: //codepen.io/anon/pen/BrXoqG

在 Safari 11.1 上返回错误:“NotSupportedError:不支持 ReadableStream 上传”。但是,如果您删除 行console.log(newRe),一切都会正常工作。

为什么?

javascript safari fetch

5
推荐指数
1
解决办法
2964
查看次数

标签 统计

fetch ×1

javascript ×1

safari ×1