2016-07-31 89 views
1

我成功將視頻添加到播放列表中,但添加了多次(有時是兩次,有時甚至更多)。任何人都可以幫忙嗎?使用Youtube API將視頻添加到播放列表

$resourceId = new Google_Service_YouTube_ResourceId(); 
$resourceId->setVideoId($videoID); 
$resourceId->setKind('youtube#video'); 

$playlistItemSnippet = new Google_Service_YouTube_PlaylistItemSnippet(); 

$playlistItemSnippet->setPlaylistId($playlistId); 
$playlistItemSnippet->setResourceId($resourceId); 

$playlistItem = new Google_Service_YouTube_PlaylistItem(); 
$playlistItem->setSnippet($playlistItemSnippet); 

$playlistItemResponse = $youtube->playlistItems->insert('snippet,contentDetails', $playlistItem, array()); 

回答

0

解決它自己,我很自豪的吧:)

我意識到AJAX是觸發鼠標懸停上面的PHP腳本。所以每次我跳過checkbox元素時,php腳本都會多次觸發。

我改變鼠標懸停代碼如下:

$(function() { 
    $('input.Chilltrap').on('click', function(e) { 
     var chilltrap = this.id;  
     if($("input[name=" + chilltrap + "]").prop('checked')) { 
      checkboxstatusCt = "Yes"; 
     } 
     else { 
      checkboxstatusCt = "No"; 
     } 
     var url = "url.php"; 
     var params = "c="+checkboxstatusCt+"&s="+chilltrap; 
     if (window.XMLHttpRequest) { 
      xmlhttp = new XMLHttpRequest(); 
     } else { 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
     xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {       
       $("#error").html(xmlhttp.responseText); 
       $("#error"). fadeIn('fast'); 
       setTimeout(function(){ 
        $("#error"). fadeOut('slow'); 
       },2000); 
      } 
     }; 
     xmlhttp.open("GET", url+"?"+params,true); 
     xmlhttp.send(); 
    }); 
}); 
相關問題