I am trying to create a function which will take a users input and use the spotify API to search for matching tracks.
This code works with the URL pointing to an internal JSON file for testing, but does not even make a request as far as I can tell when the spotify URL is entered: not even the request.always case sends out an alert. Instead, it shows the last alert ("here"). I have looked at network requests and there are none sent when the function is called. Making a request with curl in terminal works, so I know that the url is valid and working (with the search parameter filled in manually), so I am now at a loss why it won't work in this particular Javascript function.
I've been trying to fix this for over 3hrs now and any input is much appreciated. Cheers :)
function SearchForTrack(searchParameter) {
var request = $.get("https://api.spotify.com/v1/search?q=" + searchParameter + "&type=track");
request.done(function(data) {
alert(data);
DisplaySearchResults(data);
});
request.fail(function(jqXHR, textStatus, errorThrown) {
if (textStatus == 'timeout')
console.log('The server is not responding');
if (textStatus == 'error')
console.log(errorThrown);
});
request.always( function(){
alert("hello");
});
alert("here");
}