Developers!
I'm having some trouble understanding the rss feed enclosure tag.. Here you got the relevant code:
$(document).ready(function(){
$('#btnHentRss').click(function(){
fyllNyheter();
});
});
function fyllNyheter(){
var url = $('#feedListe').val();
$.getFeed({
url: "getRSS.php?url=" + url,
success: function(feed){
parseXML(feed);
},
error: function(){
$('#sectId').html("<p>Something went wrong</p>");
},
complete: function(){
}
});
}
function parseXML(feed){
$.each(feed.items, function(i, item){
var tittel = item.title;
var beskrivelse = item.description;
var url= $(item).find("enclosure['url']");
$('#sectId').append("<img src='" + media + "' />");
});
}
Example of the xml:
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/">
<channel>
<title>NRK - Musikknyheter</title>
<link>http://nrk.no/liste.rss</link>
<description>Musikknyheter</description>
<pubDate>Sat, 13 Oct 2012 16:20:47 +0200</pubDate>
<sy:updateFrequency>12</sy:updateFrequency>
<sy:updatePeriod>hourly</sy:updatePeriod>
<item>
<title>Ny slagkraftig festspillprodusent</title>
<link>http://www.nrk.no/nyheter/distrikt/troms_og_finnmark/1.8354920</link>
<description>Festspillene i Nord-Norge har ansatt Nasra Ali Omar som ny produsent for barn og unge.</description>
<pubDate>Thu, 11 Oct 2012 14:41:39 +0200</pubDate>
<enclosure url="http://www.nrk.no/contentfile/imagecrop/1.6102705?cropid=f169w225" type="image/jpeg"/>
</item>
</channel>
</rss>
var tittel
returns the correct title of each item(So I know I got contact with the feed).
var url
only returns [Object object].
I'm using jFeed. See the jFeed php and js here: http://jsfiddle.net/zbuNW/
What am I supposed to do? My google searches has turned purple, I don't want to use another plugin, and I want to do it in javascript/jquery.
Thanks for even reading my problem :) Happy problem solving!
REVISED Answer after xml was posted:
url
is an attribute of the enclosure
tag
Use:
var url = $(item).find("enclosure").attr('url')