翻過高山走不出你
2021-12-12 10:53:55
我正在使用 flickr API 構建圖像搜索程序,但遇到了某個錯誤?!拔床东@(承諾)SyntaxError:意外的令牌 < 在 JSON 位置 0 處異步函數(異步)getData @ index.js:19”我無法從 API 獲取任何數據。有人可以解釋為什么我收到這個錯誤以及如何解決它?這是 JavaScript 代碼const api_key = "123456789ABCDEFGH"; let quantity = "5";const userSearch = document.getElementById("search-field"); // input searchasync function getData() { const URL = `https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=${api_key}&per_page=${quantity}&tags=${encodeURIComponent( userSearch.value )}`; let response = await fetch(URL, { method: "GET" }); let data = await response.json(); return await data; // HERE is data error.
3 回答
qq_花開花謝_0
TA貢獻1835條經驗 獲得超7個贊
不起作用,我以前有過,然后刪除只是為了嘗試如果沒有它可以更好地工作?,F在當我再次添加時,同樣的問題..
如果你的意思是這樣:
const URL = `https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=${api_key}&per_page=${quantity}&tags=${encodeURIComponent(
userSearch.value
)}&format=json`;
鳳凰求蠱
TA貢獻1825條經驗 獲得超4個贊
我解決了它,如果其他人需要它,我會在這里解釋。還要添加:&nojsoncallback=1`
const URL = `https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=${api_key}&per_page=${quantity}&tags=${encodeURIComponent(
userSearch.value
)}&format=json&nojsoncallback=1`;
添加回答
舉報
0/150
提交
取消
