Search code examples
jqueryjsonapijsonpimdb

Parsing JSON from IMDb API


I found a way to extract data about TV shows or movies from IMDb in a comfortable JSON format: http://imdbapi.com/?t=query.
It's pretty awesome but when I try to actually use the data with local JS, it doesn't work.

var data = $.ajax({
  dataType: "json",
  async: false, 
  cache: false,
  crossDomain: true,
  jsonp: true,
  url: "http://imdbapi.com/?t=lost", 
  success: function() {
    console.log( 'loaded successfuly. ' )
  },
});
var poster = data.Poster;
console.log( poster );

I'm using JSONP because of CORS. Here's what the console shows:
"loaded successfuly.
undefined"
I don't know what is the problem! Please help.
- Oren


Solution

  • When you use data it might not been setted.... well this is the case ;). To be sure put your code in the success method.

     $.ajax({
    dataType: "json",
      async: false, 
      cache: false,
      crossDomain: true,
      jsonp: true,
      url: "http://imdbapi.com/?t=lost", 
      success: function(data) {
    
        var poster = data.Poster;
        console.log(poster);
        console.log( 'loaded successfuly. ')
      },
    });