无法加载Flickr公共API

时间:2018-12-06 16:34:05

标签: javascript json flickr fetch-api

我是新手。当我在flickr公开API https://api.flickr.com/services/feeds/photos_public.gne?format=json#的api获取错误时,请有人帮助我。感谢您的帮助。

  

SyntaxError:“ JSON.parse:JSON数据第1行第1列的意外字符”

document.getElementById("activate").addEventListener("click", () => {
  let play = document.getElementById("display");

  let url = "https://api.flickr.com/services/feeds/photos_public.gne?format=json&tags=" + document.getElementById("txtsearch").value;

  fetch(url)
    .then(resp => resp.json())
    .then(data => {
      data.items.forEach((i) => {
        const img = document.createElement("img");
        img.src = i.media.m;
        play.append(img);
      })
    })
    .catch(error => console.error(error))
});
<label>Search</label>
<input id="txtsearch" type="text"></input>
<input type="button" id="activate" value="submit"></input>

<div id="display"></div>

0 个答案:

没有答案