豆瓣電影的api
原生js用fetch發起跨域請求報錯Access-Control-Allow-Origin
于是按照提示添加了mode:'no-cors'
,最后如下,能發送請求,但是無法在回調中獲取任何數據,查詢資料后好像是第三方api不支持cors的緣故,并且在no-cors模式下允許瀏覽器發送本次跨域請求,但是不能訪問響應返回的內容,最后只能用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)
})