我正在使用 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 search
async 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.
海绵宝宝撒
qq_花开花谢_0
凤凰求蛊
相关分类