Put HTML5 to read an RSS?

2

I do not understand much of these businesses, I searched before posting here but did not find anything, I do not know if I'm looking for certain. I'm creating an app in html5, css3 and javascript. I want to add some rss to the app but I do not know how I do it, I'm new to it .. An example of rss:

link

I'm not going to post code because I do not have a code for this, because I did not find anything in the search, I only have the app ready, without the rss

    
asked by anonymous 25.05.2015 / 01:42

1 answer

2

You could easily read the feed XML with jQuery, which has functions for interpreting XML. However, to read an RSS from another site with HTML and Javascript, you will come across a security restriction, which is the Same Origin Policy . You will not be able to read content from one domain from another.

To get around this, you could create a proxy with some server language, such as PHP, Java, or ASP.NET. This proxy would read RSS content on the server and on your HTML page, with Javascript, you would make a request for your proxy.

Alternatively, you can use the Google API for RSS . It does this "proxy" for you and returns RSS content with JSON, which makes reading a lot easier. Here's an example:

 $(function () {
         var urlRss = 'http://www.windowsteam.com.br/feed/';
         $.ajax({
             type: "GET",
             url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(urlRss),
             dataType: 'json',
             error: function (xhr) {
                 var erro = xhr.responseText;
                 alert('Erro ao ler o feed: ' + erro);
             },
             success: function (xml) {
                 values = xml.responseData.feed.entries;
                 for(var i = 0; i < values.length; i++) {
                     var value = values[i];
                     var li = $("<li />");
                     li.html(value.title + "<br />" + value.content);
                     $("#result").append(li);
                 }
                 
             }
         });
     });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><ulid="result">
    
</ul>
    
25.05.2015 / 03:15