Search code examples
javascriptjqueryajaximgur

Trying to make an ajax call to the IMGUR api, data is undefined?


I'm passing in authorization headers elsewhere, so I've gotten past that problem. If I alert(data) I get an object[Object], but am at a loss as to how to extract the data from that object. Any help would be greatly appreciated! Thanks!

var albumAPI = "https://api.imgur.com/3/album/" + albumID + "/images";

$.ajax({
  url: albumAPI,
  type: 'GET',
  dataType: 'json',
  success: function(data) { 

    alert(data[0].link);

  },
  error: function() { console.log("ERRORZ"); },
  beforeSend: setHeader
});

Solution

  • If you look at the data, it contains a property called data which is an array - so get the link to the first image

    alert(data.data[0].link);