I am new to coding, so this might be a simple fix, but I am not sure what I did wrong. I am building a program that uses Spotify's API.
I'm not going to lie, this isn't a super useful program haha, but what you do is you put in an ID value for the artist and I want it to return a list of all of the albums. Here is an example of an id: 4P0dddbxPil35MNN9G2MEX
This is the error message that I get:
Does anyone know why my search result comes up as "undefined?"
Here is my JavaScript/jQuery:
var showArtistInformation = function(artistSelect){
//clone the result template
var artistResult = $('.searchResults .hiddenTemplates .artistAlbumInformation').clone();
//Set the name of the artist in the result
var theArtistName = result.find('.artistName');
theArtistName.text(artists.name);
//Get the name of the artist Album
var theAlbumName = result.find('albumName');
theAlbumName.text(album.name);
//Get the genre of the album
var theAlbumGenre = result.find('albumGenre');
theAlbumGenre.text(genre.name);
//Get the tracklisting for each Album
var theTrackNames = result.find('trackList');
theTrackNames.text(track.name);
return artistResult;
}
var getArtistAlbumInformation = function(artistID){
//the parameters that we need to pass in our request to Spotify's API
var request = {
album_type: "album"
};
$.ajax({
url: "https://api.spotify.com/v1/artists/" + artistID + "/albums",
data: request,
dataType: "jsonp",
type: "GET",
})
//What the function should do if successful
.done(function(result){
$.each(result.items, function(i,item){
var artistReturnedResult = showArtistInformation(item);
$('.artistAlbumInformation').append(artistSelect);
})
})
//What the function should do if it fails
.fail(function(jqXHR, error){
var errorElem = showError(error);
$('.search-results').append(errorElem);
});
}
//Clicking the submit button activates the function that gets the results
$(document).ready(function() {
/*Clicking the Search Button*/
$('.searchButton').on('click',function(event){
event.preventDefault();
//Zero out results if previous results have run
$('.albumArtistInformation').html('');
//End User Input
var userSearch = $(this).find("input[name='musicalArtist']").val();
getArtistAlbumInformation(userSearch);
});
})