上次更新 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);
  });
Codepen 上:https: //codepen.io/anon/pen/BrXoqG
在 Safari 11.1 上返回错误:“NotSupportedError:不支持 ReadableStream 上传”。但是,如果您删除 行console.log(newRe),一切都会正常工作。
为什么?