Advertisement
toritoesinocente

Leer RSS con jQuery

Jun 14th, 2016
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  2. <div id="noticias">...</div>
  3. <script>
  4.    //al cargar la página procesamos el RSS (XML), es necesario jQuery
  5.    $(function() {
  6.       //el archivo XML a procesar
  7.       $.get("archivoRSS.xml", function(m) {
  8.          xml = $(m);
  9.          var botija = 'Noticias'; //variable contenedor
  10.          xml.find("item").each(function(i) {
  11.             var $this = $(this);
  12.             item = {
  13.                title: $this.find("title").text(),
  14.                url: $this.find("link").text(),
  15.                image: $this.find('media\\:content,content').attr('url'),
  16.             };
  17.             botija += '<div><a href="'+item.url+'">'+(item.image?'<img src="'+item.image+'" alt="imagen" /><br />':'')+item.title+'</a></div>';
  18.       });
  19.       //establecemos el contenido de $botija al nodo  #noticias
  20.       setTimeout(function() {
  21.          $("#noticias").html(botija);
  22.       },1000);
  23.    },'xml');
  24. });
  25. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement