0

How can i get from JSON imdbID column into div id? this is my code:

const settings = {
  async: true,
  crossDomain: true,
  url: 'https://movie-database-imdb-alternative.p.rapidapi.com/?s=' + res + '&r=json&y=[xfvalue_jahre]&page=1',
  method: 'GET',
  headers: {
    'x-rapidapi-host': 'movie-database-imdb-alternative.p.rapidapi.com',
    'x-rapidapi-key': '137f269ad5m5jsn65ff6dcb7b43',
  },
};

$.ajax(settings).done(function (data) {
  console.log(JSON.stringify(data.imdbID)); //doesnt work:(
  document.getElementById('imdbid').value = data.imdbID; //doesnt work:(
});

JSON results

{
  "Search": [
    {
      "Title": "Paddington 2",
      "Year": "2017",
      "imdbID": "tt4468740",
      "Type": "movie",
      "Poster": "https://m.media-amazon.com/images/M/MV5BMmYwNWZlNzEtNjE4Zi00NzQ4LWI2YmUtOWZhNzZhZDYyNmVmXkEyXkFqcGdeQXVyNzYzODM3Mzg@._V1_SX300.jpg"
    }
  ],
  "totalResults": "1",
  "Response": "True"
}
pilchard
  • 12,414
  • 5
  • 11
  • 23
  • You need to get inside the `data.Search` array. If there is only one item in array try `data.Search[0].imdbID` – charlietfl Nov 25 '21 at 23:23
  • An issue with that code is .value, you're working with a div element, so you need to use for example .innerHTML. ||| document.getElementById('imdbid').innerHTML = "some info"; – Cr4id3r Nov 25 '21 at 23:28
  • omg thx it works !! i did same but with lowercase and it doesnt work -.- – Alexander Schulz Nov 25 '21 at 23:31

0 Answers0