So I've looked through SO and the interwebs for some guiding light but can't find anything that hits the nail on the head.
I'm trying to return a value from a function. The following will present the data in an alert, so I know it's the proper value is coming back from the JSON call:
function getTitle(){
var q= 'https://www.googleapis.com/youtube/v3/videos?id=[VIDEOID]&key=[APIKEY]&fields=items(snippet(title))&part=snippet'
$.ajax({
url: q,
dataType: "text",
success: function(data){
data = JSON.parse(data);
alert(data.items[0].snippet.title);
}
});
}
getTitle();
But when I try to return the data from the function like so:
function getTitle(){
var q= 'https://www.googleapis.com/youtube/v3/videos?id=[VIDEOID]&key=[APIKEY]&fields=items(snippet(title))&part=snippet'
$.ajax({
url: q,
dataType: "text",
success: function(data){
data = JSON.parse(data);
return data.items[0].snippet.title;
}
});
}
alert(getTitle());
I get undefined.
If anyone could tell me where I'm being a bonehead I would appreciate it.