在用 fetch API 实现跨域请求时,遇到这个问题,跨域请求是成功的,但是返回的 response 中 body 为 null ,response.ok==false,
在chrome浏览器可以看到,返回的数据已经有了,
我使用是fetch获取百度音乐API的,我写的代码如下:
var url="http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.search.catalogSug&query=张碧晨"
fetch(url, {
method: 'GET',
mode: 'no-cors',
cache: 'default'
}).then((res)=> res.json()).then((resData) => {
console.log(resData);
})
这样打印出来的,显示有错误,不知道是什么问题?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…