0

I am newbie here. Please someone help me as i having this error on fetch api to flickr public api https://api.flickr.com/services/feeds/photos_public.gne?format=json#. Appreciates on your help.

SyntaxError: "JSON.parse: unexpected character at line 1 column 1 of the JSON data"

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>
  • The URL isn't returning JSON. – Quentin Dec 06 '18 at 16:44
  • For an explanation of why this question was marked as a duplicate, see the Callback Function section of [these Flickr API docs](https://www.flickr.com/services/api/response.json.html). – MTCoster Dec 06 '18 at 16:45
  • Found it and thanks. Just add on nojsoncallback=1 into the url –  Dec 06 '18 at 17:04

0 Answers0