简体   繁体   English

如何动态加载Feedburner RSS?

[英]How can I load Feedburner RSS dynamically?

My website is dynamic, so in a sense, the website is only one page, but that one page (Home Page) loads different content depending on links pressed, url changes, etc.. On my navigation bar, I have different links: about, blog, portfolio, resume, and contact. 我的网站是动态的,因此从某种意义上说,该网站只有一页,但是一页(主页)根据所按下的链接,URL更改等加载不同的内容。在我的导航栏上,我有不同的链接:关于,博客,作品集,简历和联系方式。 When I click on blog, I want to (1) load the blog.html code into the body of my Home Page and (2) execute the external javascript code that loads my blog RSS by Feedburner. 当我单击博客时,我想要(1)将blog.html代码加载到我的主页body ,以及(2)执行外部JavaScript代码,以通过Feedburner加载我的博客RSS。

I've tried: 我试过了:

  • $.getScript(...);
  • creating a script tag dynamically 动态创建script标签
  • $(window).ready(...);

Note: I can't put the script tag in Home Page's head tag because wherever the script tag is, is where the external code is displayed (and I need it displayed in <div class='content' id='blog-page'> . 注意:我不能将script标记放在Homepage的head标记中,因为无论script标记在哪里,外部代码的显示位置(我都需要在<div class='content' id='blog-page'>

Home Page: 主页:

<html>
   ...
   <body>   
      <div id="content"></div> <!-- Dynamic div -->

      <script>
         <!-- updateContent is called when URL changes, page loads, etc... -->
         function updateContent(page) {
            $('div#content').load('../../' + page + '.html');
         };
      </script>
   </body>  
</html>

Dynamic Content (pulled into Home Page): 动态内容(放入首页):

<div class='content' id='blog-page'>
   <script src="http://feeds.feedburner.com/blogspot/bVDtI?format=sigpro" type="text/javascript"></script>
...
</div>

Any Ideas???? 有任何想法吗???? I'm at a total loss... 我完全不知所措...

Found the answer. 找到了答案。

That script uses document.write and has to be placed where the output is needed.. 该脚本使用document.write,必须放置在需要输出的位置。

I suggest to use Google Feed API for dynamically reading the blog RSS/Atom like this 我建议像这样使用Google Feed API动态读取博客RSS / Atom

http://jsbin.com/UyoYOvO/1/ http://jsbin.com/UyoYOvO/1/

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>

    $(document).ready(function(){
        // Data object: RSS feed URL, number of entries to return, result format, API version
        var data = {
            q: 'http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml'
            , num: 10
            , output: 'json'
            , v: '1.0'
        };

        // AJAX call to Google Feed API which converts ATOM/RSS feed to JSON
       $.ajax({
            url:'http://ajax.googleapis.com/ajax/services/feed/load'
            ,type : "GET"
            ,dataType : "jsonp"
            ,data: data
            ,success: function (json) {
                var feed = json.responseData.feed;
                if(!feed) return;
                var entries = feed.entries;
                if(!entries) return;

                var html = '';
                for( var i=0; i<entries.length; i++){
                    html += '<h2><a href="'+ entries[i].link +'">'+ entries[i].title +'</a></h2>' +
                          '<p>'+ entries[i].contentSnippet +'</p>';
                };

                $('#output').html( html);
            }
      });
  })
</script>
</head>
<body>

    <div id="output"></div>

</body>
</html>

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

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