Hello! I was told I may find help here. I'm trying to fetch jSON info from Youtube on a videos, and then append them to the source but I'm having issues getting the JSON info into an array to use in my FOR loop where it goes over each video.... :\
This is what I'm attempting currently.
- // Get youtube info
- function parseresults(target) {
- var parseResults = $.getJSON(target);
- return parseResults;
- }
- function getComments(commentsURL, startIndex) {
- $.ajax({
- url: commentsURL + '&start-index=' + startIndex,
- dataType: "jsonp",
- success: function (data) {
- $.each(data.feed.entry, function(key, val) {
- var returnArray = { 'author': val.author[0].name.$t, 'comment': val.content.$t };
- commentsArray.push(returnArray);
- });
- if ($(data.feed.entry).size() == 50) { getComments(commentsURL, startIndex + 50); }
- }
- });
- }
-
- function appendFeaturedVideos() {
- $.get('http://jordan.rave5.com/tmpstuff/featVideos.txt',function(data){
- var lineArray=data.split('\n'),
- slideList=[],
- featVids = $('#featured-video-links');
- count = lineArray.length;
- for(i = 0; i < count; i++) {
- var feedUrl = 'http://gdata.youtube.com/feeds/api/videos/' + lineArray[i] + '?v=2&alt=json',
- videoUrl = 'http://www.youtube.com/embed/' + lineArray[i] + '?fs=1';
- parseResults = parseresults(feedUrl);
- featVids.append('<div id="featured-video-link"><img src="' + parseResults['thumbnail']['sqDefault'] + '" alt="' + parseResults['title'] + '" /><div id="feat-vid-info"><div id="feat-vid-title"><div id="feat-vid-views">' + parseResults['viewCount'] + '</div>' + parseResults['title'] + '</div><p class="feat-vid-author">' + parseResults['uploader'] + '</p></div></div>');
-
- }
- });
-
- }
-
- $(document).ready(function() {
-
- appendFeaturedVideos();
-
- });