Javascript Youtube iframe api未在ajaxcall后创建OnyOutubeiFrameAPReady
我在通过YouTubeiFrameAPReady加载iframe播放器时遇到问题。我建了一个视频传送带。我在onYouTubeIframeAPIReady()内的ajax调用后创建播放器对象。我正在通过ajax从数据库中获取所有视频ID,并构建iframe 现在的问题是有时iframe没有加载。当用户单击旋转木马图像时,由于未生成iframe,视频不会播放。这是在生产和舞台环境中发生的 这是我的密码Javascript Youtube iframe api未在ajaxcall后创建OnyOutubeiFrameAPReady,javascript,jquery,html,ajax,iframe,Javascript,Jquery,Html,Ajax,Iframe,我在通过YouTubeiFrameAPReady加载iframe播放器时遇到问题。我建了一个视频传送带。我在onYouTubeIframeAPIReady()内的ajax调用后创建播放器对象。我正在通过ajax从数据库中获取所有视频ID,并构建iframe 现在的问题是有时iframe没有加载。当用户单击旋转木马图像时,由于未生成iframe,视频不会播放。这是在生产和舞台环境中发生的 这是我的密码 var tag = document.createElement('script'); tag.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
jQuery.ajax({
type: "POST",
async: false,
url: "load-carousel-videos",
success: function(rtn){
var player_obj = Array();
if(rtn !='false'){
var keyVar = jQuery.parseJSON(rtn);
jQuery.each(keyVar, function(key, val) {
player[key] = new YT.Player('vidContainer'+key, {
height: '370',
width: '654',
videoId: val,
playerVars: {'wmode':'transparent','controls':1,'modestbranding':0,'autoplay':autoplay_status,'showinfo':1,'rel':0},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
});
}
}
});
}
下面的iframe有时加载,有时不在HTML主体下
<iframe width="654" height="370" title="YouTube video player" class="video_container" id="vidContainer21" src="https://www.youtube.com/embed/zOPip3r8G80?wmode=transparent&controls=1&modestbranding=0&autoplay=1&showinfo=1&rel=0&enablejsapi=1&origin=http%3A%2F%2F148-177-29-187.itrinno.com" frameborder="0" allowfullscreen="1" style="display: none;" type="text/html"></iframe>