2013-12-19 112 views
0

希望你伟大的人可以帮助我这个(可能很容易)的问题。加载RSS链接里面div

我有以下的HTML

<div id="rssfeed"></div> 

和JS包括FeedEK plugin

$(document).ready(function() { 
    $('#rssfeed').FeedEk({ 
     FeedUrl: 'http://www.essent.nl/content/system/xml/rss_nieuws.rss', 
     MaxCount: 5, 
     ShowDesc : false 
    }); 
}); 

的RSS源得到完美的显示。链接在新窗口中默认打开,我不想。

我的问题是如何将RSS项目的内容加载到相同的div中。 例如,当我点击某个链接时,该RSS项目的内容应加载到#rssfeed之内。 应该出现一个返回按钮以回到RSS提要。

我知道AJAX应该涉及到将HTML内容解析为#rssfeed。但我不知道如何使用AJAX附加RSS项目的URL。

提前致谢!

+0

如果您加载RSS链接通常是链接到网页,它会影响您的布局。如果您确定,如果您的布局中有足够的空间来显示整个网页,则可以执行此操作。 –

回答

0

我可能有一个外部脚本解析RSS feed到json中,然后你可以使用ajax将它加载到yr RSS div中。这样你可以更好地控制布局和内容。

这应该是一个评论,但我不能发布它们!对不起,我会试着在这里发布一些示例代码,当我不在我的手机上也:

编辑:

确定 - 这里是一个不完整的答案,但希望应该指向你在正确的方向。

例如PHP解析RSS:

<?php 
header('Content-type: application/json'); 

$feed = file_get_contents('http://www.essent.nl/content/system/xml/rss_nieuws.rss'); 
$xml = new SimpleXmlElement($feed); 

foreach($xml->channel->item as $i){ 
    echo json_encode($i); 
} 
?> 

你想要创建自己的数据结构出于此,而不仅仅是它echo'ing到屏幕上。使输出可供选择:

示例输出

{ 
    "title": "this is a title", 
    "description": "this is the description", 
    "link": "this is the link to the content" 
}, 
{ 
    "title": "this is another title", 
    "description": "this is another description", 
    "link": "this is another link to the content" 
}, 
{ 
    "title": "etc", 
    "description": "etc", 
    "link": "etc" 
} 

现在在你的JavaScript你想要的东西加载:

<script> 
    $.get('myphpoutput.php', function(){ 
     //do stuff with the json for display 
    }) 
</script> 

通过这种方法,你的PHP的过程中遇到了内容总量控制JavaScript阶段。希望这可以帮助!

+1

Ofcourse,解析RSS。将等待您的脚本! – D4NH