Reputation: 697
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. 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. Any help please?
JSFiddle: http://jsfiddle.net/nLz8k31v/
Upvotes: 2
Views: 268
Reputation: 144729
jQuery itself parses the response for you, i.e. the data
is already XML-parsed. Just pass the data
to the jQuery constructor.
$.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
.
jQuery.parseXML = function( data ) {
var xml;
if ( !data || typeof data !== "string" ) {
return null;
}
// ...
};
Upvotes: 3