0

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. 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.

I've tried:

  • $.getScript(...);
  • creating a script tag dynamically
  • $(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'>.

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.

Community
  • 1
  • 1
Bob Smith
  • 17
  • 4

1 Answers1

3

That script uses document.write and has to be placed where the output is needed..

I suggest to use Google Feed API for dynamically reading the blog RSS/Atom like this

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>
Michael B.
  • 2,798
  • 1
  • 14
  • 18