0

I've tried to solve this with async false, but to no avail.

I use the method below to call a poster with a JSON api I call which I letter assign to the global variable img_path.

function getPoster(id) {
var poster_path = null;

$.getJSON( "https://api.moviedb.org"+id+"?", {async: false}, function( data ) { 
        poster_path = data.poster_path;
    }
}

For whatever reason, it doesn't work as the variable will still be "null" when I try to display it on my HTML-page. I checked in the and could confirm that the variables aren't reassigned properly. The reassignment doesn't work as if the global variable is outside the JSON-methods scope.

Help would be greatly appreciated!

user1531921
  • 1,372
  • 4
  • 18
  • 36
  • Try to put a `console.log(data)` inside the callback, do you see the data in the console? Also the moviedb.org domain doesn't seem to exist, did you mean themoviedb.org? – Kerstomaat Jan 19 '14 at 23:30
  • You *can* access and write to the global variable. You have identified the problem: The variable is still `null` ***when*** you try to display it. – Bergi Jan 19 '14 at 23:30
  • https://api.moviedb.org"+id+"?" a r sure? or .org/"+id – JOE LEE Jan 19 '14 at 23:36

0 Answers0