title: Youtube iframe api not creating onYouTubeIframeAPIReady after ajaxcall
body: <p>I'm facing trouble in loading iframe player via YouTubeIframeAPIReady. I have built a video carousel. I'm creating the player objects after ajax call within onYouTubeIframeAPIReady(). I'm fetching all the video ids from the database via ajax and building the iframe.</p>
  
  <p>Now the problem is sometimes the iframe is not loading. When user clicking on the carousel image the video is not playing as no iframe has been generated. This is happening in production and stage environments.</p>
  
  <p>Here is my code</p>
  
  <pre><code>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
            }
          });
  
        }); 
      }
    }
   });
  }
  </code></pre>
  
  <p>Below iframe is sometime loading and sometimes not under HTML body</p>
  
  <pre><code>&lt;iframe width="654" height="370" title="YouTube video player" class="video_container"  id="vidContainer21" src="https://www.youtube.com/embed/zOPip3r8G80?wmode=transparent&amp;amp;controls=1&amp;amp;modestbranding=0&amp;amp;autoplay=1&amp;amp;showinfo=1&amp;amp;rel=0&amp;amp;enablejsapi=1&amp;amp;origin=http%3A%2F%2F148-177-29-187.itrinno.com" frameborder="0" allowfullscreen="1" style="display: none;" type="text/html"&gt;&lt;/iframe&gt;
  </code></pre>