代碼 :async function getNews() { const response = await fetch('http://newsapi.org/v2/top-headlines?country=in&pageSize=1&apiKey=a876816f98574cdfa23ffdc7d531c7bc'); const jsonResp = await response.json(); return jsonResp;}n = await getNews();Google Chrome 控制臺中顯示的錯誤:CORS 策略已阻止從來源 'chrome-search://local-ntp' 訪問 'http://newsapi.org/v2/top-headlines?country=in&pageSize=1&apiKey=a876816f98574cdfa23ffdc7d531c7bc' -Control-Allow-Origin' 標頭存在于請求的資源上。如果不透明的響應滿足您的需求,請將請求的模式設置為“no-cors”以獲取禁用 CORS 的資源。GET http://newsapi.org/v2/top-headlines country=in&pageSize=1&apiKey=a876816f98574cdfa23ffdc7d531c7bc net::ERR_FAILED getNews @ VM88:2 (匿名) @ VM94:1未捕獲的類型錯誤:無法獲取鏈接到錯誤圖像
使用 Java Script fetch 命令從 google chrome 控制臺請求新聞 API
桃花長相依
2022-10-13 17:13:36