/    Sign up×
Community /Pin to ProfileBookmark

Hi everyone. I want to implement in my site a rss news reader. In my country we have a newspaper named Clarin, wich offers rss services. In example, Clarin offers [url]http://www.clarin.com/suplementos/viajes/ultimo/viajes.xml[/url] file for reading new about travels and tourism. In my site, I want to implement somehow a script that do the following:

  • Load xml file

  • Parse when is loaded

  • Show news on user’s screen
  • The truth is that I’m having trouble in first step. I have this script to show the server’s response:

    <script>
    var obj = new HttpRequest();
    obj.setResponseType(1);
    obj.oncomplete = function(){
    document.getElementById(‘rss’).innerHTML = obj.getResponse();

    }
    obj.loadAsync(‘www.clarin.com/suplementos/viajes/ultimo/viajes.xml’);
    </script>

    HttpRequest is an object wich implements Ajax. This object works well. With obj.setResponseType(1) I determine that server’s response will be plain text. obj.oncomple is the function wich is executed when the ajax object is in readyState 4 (complete). obj.loadAsync is actually the function that allows me to load a file asynchronously. The code works well, but it shows the ‘Page Not Found’ screen. I check one thousand times the path of the file and it’s correct. So, what’s happening here?. Is this the way to implement rss news reader from javascript?. Regards.

    to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @A1ien51Jul 26.2008 — JavaScript has a same domain policy. It can not talk to other domains. Therefore you can not request that XML document. You would have to use a serverside proxy to fetch the XML.

    Eric
    Copy linkTweet thisAlerts:
    @rnd_meJul 27.2008 — [CODE]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>rss test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body onload="boot()">
    <div id='news'></div>

    <script type='text/javascript'>

    function el(tid) {return document.getElementById(tid);}
    function JSget(turl) {var xJs = document.createElement("script");xJs.type = "text/javascript";var h = document.getElementsByTagName("head");if (h && h[0]) {h[0].appendChild(xJs);}xJs.src = turl;return xJs;}
    function getFeed(feed, callback) {var src = "http://pipes.yahoo.com/pipes/9oyONQzA2xGOkM4FqGIyXQ/run?&_render=json&_callback=" + callback + "&feed=" + feed;if (feed.match && feed.match(/pipes.yahoo.com/)) {src = feed + "?_render=json&_callback=" + callback;}JSget(src);}


    function rssCallback(a) {
    var items = a.value.items;
    var output = [];
    for (var i = 0, mx = items.length; i < mx; i++) {
    var it = items[i];
    output[i] = it.title.link(it.link).bold() + " <br> " + it.pubDate + "<br>" + it.description;
    }
    el("news").innerHTML = output.join("<br><br>");
    }

    function boot(){
    getFeed("http://www.clarin.com/suplementos/viajes/ultimo/viajes.xml", "rssCallback")
    }

    </script>
    </body>
    </html>
    [/CODE]
    ×

    Success!

    Help @mariano_donati spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...