豆瓣電影的api
原生js用fetch發(fā)起跨域請(qǐng)求報(bào)錯(cuò)Access-Control-Allow-Origin
于是按照提示添加了mode:'no-cors'
,最后如下,能發(fā)送請(qǐng)求,但是無法在回調(diào)中獲取任何數(shù)據(jù),查詢資料后好像是第三方api不支持cors的緣故,并且在no-cors模式下允許瀏覽器發(fā)送本次跨域請(qǐng)求,但是不能訪問響應(yīng)返回的內(nèi)容,最后只能用ajax
let domain=`http://api.douban.com/v2/movie/top250`
fetch(this.domain,{
start:0,
count:20,
method:'GET',
mode:'no-cors'
}).then(response=>{
console.log(response)
console.log(response.json())
return response.json()
}).then(res=>{
console.log(res)
}).catch(e=>{
console.log(e)
})