简体   繁体   English

jQuery $ .get和$ .parseXML获取Vimeo视频时长

[英]jQuery $.get and $.parseXML to get Vimeo video duration

I need to get duration of specific video on vimeo before I've even loaded it player, so I see no other options rather than make an AJAX call and trying to get information about video. 在加载播放器之前,我需要在vimeo上获取特定视频的时长,因此,除了进行AJAX调用并尝试获取有关视频的信息外,我没有其他选择。 I've prepared the following structure: 我准备了以下结构:

$.get( "http://vimeo.com/api/v2/video/8957328.xml", function( data ) {
  var xmlDoc = $.parseXML(data),
  $duration = $(xmlDoc).find("title");
  $('div').html($duration.text());
});

As I can say, XML is parsed properly, but I'm not able to get final data, and I don't even have an idea why it's not working. 可以说,XML已正确解析,但是我无法获取最终数据,甚至不知道为什么它不起作用。 Any help please? 有什么帮助吗?

JSFiddle: http://jsfiddle.net/nLz8k31v/ JSFiddle: http : //jsfiddle.net/nLz8k31v/

jQuery itself parses the response for you, ie the data is already XML-parsed. jQuery本身会为您解析响应,即data已经经过XML解析。 Just pass the data to the jQuery constructor. 只需将data传递给jQuery构造函数即可。

$.get( "http://vimeo.com/api/v2/video/8957328.xml", function( data ) {
  var $xmlDoc = $(data),
      $duration = $xmlDoc.find("title");
  $('div').html($duration.text());
});

Your code doesn't work as the passed value to the $.parseXML is not a string and the .parseXML method returns null . 您的代码无效,因为传递给$.parseXML值不是字符串, 并且.parseXML方法返回null

jQuery.parseXML = function( data ) {
    var xml;
    if ( !data || typeof data !== "string" ) {
        return null;
    }
    // ...
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM