I'm trying to request data from a certain API and then i would need to put the response into variables but the variables are empty when i try to use them later on. When inserting the "data.id" f.e into a html code block it works like it should but variables are just left out.
Here is my code, I would be thankful for any help or advice.
var id;
var title;
var posterPath;
var overview;
var releaseDate;
var actors = [];
var urlData = 'https://api.themoviedb.org/3/movie/' + a.getAttribute('id') + '?api_key=a************************&language=en-US';
$.get(urlData, function(data) {
console.log('data', data)
id = data.id
title = data.title
posterPath = data.poster_path
overview = data.overview
realeaseDate = data.release_date
document.getElementById("movieData").innerHTML += "<div data-role='header'><h2>" + data.title + "</h2><p>Release date: " + data.release_date + "</div><div data-role='content'><img src='https://image.tmdb.org/t/p/w500/" + data.poster_path + "' width=50% height=80%></div>"
document.getElementById("description").innerHTML += "<p style='white-space:normal;'>" + data.overview + "</p>"
})