我之前問過另一個問題,並試圖獲得有關從YouTube搜索查詢中獲取XML文件的一些代碼的幫助。然後,使用jQuery,從XML文件(視頻ID)獲取所需的信息並將其放入JavaScript變量。使用jQuery將XML中的搜索結果放入數組中
這工作得很好,但我想(如果可能的話)我們的網站沒有1但3個來自此頻道的最新視頻。我被建議改變搜索得到3結果,而不是一個,並將jQuery .find()結果放入一個數組中。
問題是,我認爲(我真的應該說,我敢肯定)我做了這個錯誤......看看:
<!-- enable jQuery -->
<script type="application/javascript" src="jquery.js"> </script>
<!-- video loading functions -->
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery.ajax('https://gdata.youtube.com/feeds/api/videos?author=inthegamesroom&orderby=published&prettyprint=true&start-index=1&max-results=3&v=2',{
dataType:'xml',
success: function(data,status, xhr) {
var $data =$(data);
var videoTag = new array ($data.find('videoid'));
var videoId1 = videoTag[0].text();
var videoId2 = videoTag[1].text();
var videoId3 = videoTag[2].text();
}
});
// YouTube Video embed command
function embedYT1(id, loaction) {
jQuery(location).append("<object width=\"1000\" height=\"563\"><param name=\"movie\" value=\"https://www.youtube.com/v/"+id+"?version=3&hl=en_US\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"https://www.youtube.com/v/"+id+"?version=3&hl=en_US\" type=\"application/x-shockwave-flash\" width=\"1000\" height=\"563\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed></object>")
}
// Call video embed function for 3 vids
embedYT(videoId1, '#vid1');
embedYT(videoId2, '#vid2');
embedYT(videoId3, '#vid2');
});
</script>
誰能幫助?
您可能還會注意到,我有一個embedYT功能,用於嵌入3個視頻。我做對了嗎? (我有三個id='vid#'
在我的標籤爲我的表。
那的幫助的感謝負荷!我注意到,因爲看起來我需要更改'#vidX'以vid0而不是vid1開頭。無論哪種方式,頁面仍不會顯示任何嵌入的視頻。後面的id標記看起來像這樣:'< td height =「563」colspan =「2」id =「vid0」>'有什麼想法? – th3ant
我試過這段代碼,它似乎'$ data.vind('videoid')'返回一個空集。我還發現了一些其他的錯誤。讓我更新答案 – afgomez
謝謝,我記得它是'',但是當我試着用它加載一個視頻時,它沒有發現任何東西和我所做的代碼..我不敢說我仍然沒有得到它工作原因不明。如果你不介意看看它,我會粘貼html文件[here](http://pastebin.com/yLG5YYcy)。 (該網站是在Dreamweaver中,所以還有一些其他的JS代碼..和一些圖片元素將會丟失。在先進的感謝:) –
th3ant