views:

24

answers:

1

Hi Everyone

I am writing a code using Google-Ajax-Feed-API to get latest feeds from some site. I want the feeds to be checked for update every(say 1 secs?). I am able to retrieve the blogs but not able to refresh the DIV tags. Any help will be useful.

 <script type="text/javascript">
        google.load("feeds", "1");
        $(document).ready(function(){
          setInterval(  initialize(),10000)
        }); 
          function initialize() {
            var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
            feed.setNumEntries(6);
            feed.load(function(result) {
                if (!result.error) {
                    var container = document.getElementById("feed");
                    for (var i = 0; i < result.feed.entries.length; i++) {
                        var entry = result.feed.entries[i];
                        var div = document.createElement("div");
                        div.appendChild(document.createTextNode(entry.title));
                        container.appendChild(div);
                    }
                }
            });
    }
    </script>

Thanks.

+1  A: 
setInterval('initialize()',10000)

You need the quotes

To refresh every 1 second use:

setInterval('initialize()',1000)
NicolasT
Thanks man.That did solve the initial problem, however, the new information is appended in the DIV tag. how to overwrite the feeds? ie I just want(say 4) latest feeds. the above code starts with 4 and after each refresh adds 4 more to it. Any help?
to empty the container before appending new nodes, use `while (container.hasChildNodes()) {container.removeChild(container.firstChild);}`
Anurag
after var container = document.getElementById("feed"); put $(container).empty();
NicolasT
Cool.But this works well in Mozilla, however in IE nothing appears to happend(div is not updating and seems like caching problem). Why is this so and how to overcome this?Thanks.