Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Youtube iframe api未在ajaxcall后创建OnyOutubeiFrameAPReady_Javascript_Jquery_Html_Ajax_Iframe - Fatal编程技术网

Javascript Youtube iframe api未在ajaxcall后创建OnyOutubeiFrameAPReady

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.

我在通过YouTubeiFrameAPReady加载iframe播放器时遇到问题。我建了一个视频传送带。我在onYouTubeIframeAPIReady()内的ajax调用后创建播放器对象。我正在通过ajax从数据库中获取所有视频ID,并构建iframe

现在的问题是有时iframe没有加载。当用户单击旋转木马图像时,由于未生成iframe,视频不会播放。这是在生产和舞台环境中发生的

这是我的密码

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&amp;controls=1&amp;modestbranding=0&amp;autoplay=1&amp;showinfo=1&amp;rel=0&amp;enablejsapi=1&amp;origin=http%3A%2F%2F148-177-29-187.itrinno.com" frameborder="0" allowfullscreen="1" style="display: none;" type="text/html"></iframe>