【问题标题】:JS works perfect on home machine, not so much on serverJS 在家用机器上完美运行,而不是在服务器上
【发布时间】:2011-05-14 14:50:19
【问题描述】:

我正在从 youtube 中提取一些视频,以显示在网站的多媒体页面上。这段代码一直运行良好,但现在,神秘地,它被破坏了。在我的家用机器上进行测试显示一切正常。知道为什么会发生这种情况吗? (注意:wordpress 站点,js 在 WP 帖子外部,代码可见 @github,使用浏览器工具或在线 js lint 没有明显错误)

提前谢谢...

Javascript:

$(document).ready(function() {
  //some variables
  var videos = [];                      //placeholder for video information returned from youtube
  var video_elm_arr = $('.video');      //array of 'video' elements in DOM      
  //hide videos until ready
  $('.video').addClass('hidden');      
  //pull video data from youtube
  $.ajax({
    url: 'http://gdata.youtube.com/feeds/api/users/danwoodson/uploads?alt=json',
    dataType: 'jsonp',
    success: function(data) {
      alert(data);
      $.each(data.feed.entry, function(i,item){
        //only take the first 7 videos
        if(i > 6)
          return;              
        //create object to hold the video's info
        videos[i] = {};
        videos[i].title = item.title.$t;
        videos[i].url = item.media$group.media$content[0].url;          //this will need to be cleaned before use
        videos[i].summary = item.content.$t;   
        videos[i].thumbnail = item.media$group.media$thumbnail[3].url;              
        //assign title
        $(video_elm_arr[i]).find('.video_title').append(videos[i].title);            
        //clean url
        var video_url = videos[i].url;
        var index = video_url.indexOf("?");
          if (index > 0)
            video_url = video_url.substring(0, index);
        //and re-assign
        videos[i].url = video_url;                         
        if(i == 0){ //only for featured/main
          //insert flash object in video element
          $(video_elm_arr[i]).find('.video_title').after('<object id="video_0" width="475" height="267.1875">' + 
                                   '<param name="movie" value="' + video_url + '&showinfo=0"></param>' +
                                   '<param name="allowFullScreen" value="true"></param>' +
                                   '<param name="allowscriptaccess" value="always"></param>' +
                                   '<embed src="' + video_url + '&showinfo=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="475" height="267.1875"></embed>' +
                                   '</object>');
          //and include summary
          $(video_elm_arr[i]).find('#featured_summary').html(videos[i].summary);
        }
        else{ //else just use thumbnail and enlarge
          $(video_elm_arr[i]).find('.video_title').after('<img src="' + videos[i].thumbnail +'" alt="video" id="video_' + i + '" />');
          $(video_elm_arr[i]).find('img').animate({height: 84.375, width: 150}, 500);            
        }                       
        //and finally show
        $(video_elm_arr[i]).removeClass('hidden');
      });
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {alert("error with retrieving videos");}
  });      
  //create functionality
  $('.non_featured').bind('click', function(){
    //get clicked video's id
    var clicked_vid_id = $(this).find('img').attr('id');
    //clean
    var index = clicked_vid_id.indexOf("_");
    if (index > 0)
      clicked_vid_id = clicked_vid_id.substring(index+1);        
    //get featured video's id
    var cur_featured_vid_id = $('#featured').find('object').attr('id');
    //clean
    var index = cur_featured_vid_id.indexOf("_");
    if (index > 0)
      cur_featured_vid_id = cur_featured_vid_id.substring(index+1);        
    //create new swf object with clicked video's information
    var new_featured_vid_swf = '<object id="video_' + clicked_vid_id + '" width="475" height="267.1875">' + 
                               '<param name="movie" value="' + videos[clicked_vid_id].url + '?showinfo=0&autoplay=1"></param>' +
                               '<param name="allowFullScreen" value="true"></param>' +
                               '<param name="allowscriptaccess" value="always"></param>' +
                               '<embed src="' + videos[clicked_vid_id].url + '?showinfo=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="475" height="267.1875"></embed>' +
                               '</object>';        
    //clear out clicked video's image
    $(this).find('img').remove();               
    //clear out featured video's original swf object
    $('#featured').find('object').remove();                
    /*assign newly created swf objects to their appropriate locations*/
    //set clicked
    $(this).find('.video_title').html(videos[cur_featured_vid_id].title);
    $(this).append('<img src="' + videos[cur_featured_vid_id].thumbnail +'" alt="video" id="video_' + cur_featured_vid_id + '" />');
    $(this).find('img').animate({height: 84.375, width: 150}, 500);
    //and set new featured/main
    $('#featured').find('.video_title').html(videos[clicked_vid_id].title);
    $('#featured').find('.video_title').after(new_featured_vid_swf);
    $('#featured').find('#featured_summary').html(videos[clicked_vid_id].summary);        
  });
});

【问题讨论】:

  • 你用什么代码来拉取 YouTube 视频?
  • “它坏了”是什么意思?帮助我们帮助您:发布最少的相关代码、浏览器错误、HTTP 请求日志等。如果没有更多上下文,源代码链接将无济于事。
  • 如果您使用 Chrome 的开发者工具检查任何错误,这将非常有帮助。监控 XHR 和 JavaScript 是否存在可能的故障。
  • WordPress“网站”的链接怎么样?
  • @Joel:我一直在使用 CDT 来检查 js 错误,但不是 XHR。会的。

标签: javascript jquery api wordpress youtube


【解决方案1】:

在您的页面中,这些是发生的错误。 Internet Explorer、Chrome 和 Firefox 都有很好的调试器/JavaScript 控制台来显示这些信息。

'pollsL10n' is undefined  polls-js.js?ver=2.50, line 1 character 62
pollsL10n.show_loading=parseInt(pollsL10n.show_loading)


Object doesn't support this property or method  headcount-multimedia, line 135 character 9
$(".tweet").tweet({


Object doesn't support this property or method  slider.js, line 32 character 4
jQuery("#main-photo-slider").codaSlider();

Object doesn't support this property or method  main.js, line 31 character 1
jQuery.cookie('widget widget_text');

【讨论】:

  • 对。这些错误在页面停止工作之前就已经存在,而我没有做过任何工作(我是实习生)。我仍然觉得 jQuery 找到选择器是个问题(这太奇怪了......)
  • 弄清楚为什么 jQuery 没有找到选择器。现在它找到了它们,但仍然没有添加它应该添加的内容
  • 上述错误可能会干扰这些脚本中该点之后出现的任何内容。脚本在发生时停止执行……可能与您看到的问题有关,也可能无关。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-26
相关资源
最近更新 更多