【发布时间】:2017-03-04 03:03:31
【问题描述】:
我想使用 fetch API 从 URL 获取整个 HTML 文档。
let config = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'text/html',
'Accept-Language': 'zh-CN',
'Cache-Control': 'no-cache'
},
mode: 'no-cors'};
fetch('http://www.baidu.com', config).then((res)=> {
console.log(res);}).then((text)=> {});
当我在 chrome 中运行代码时,它会触发一个请求并在 chrome 网络选项卡中返回 html。但 fetch res 返回:
为什么状态为 0,我怎样才能获得像 chrome 网络中的那样正确的 res ?
【问题讨论】:
-
状态 0 依赖于库,
fetch函数来自哪个库? -
fetch是本机函数(现在)。
标签: javascript ajax frontend