RSS & Javascript

I’m trying to read in data from a percussion RSS feed and then parse it and return it to a UL list. I have the following code but it’s not working at all. Any suggestions?


  
<title>XML &amp; AJAX</title>   
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript"></script>   
<script type="text/javascript"> <br />
 $(document).ready(function(){ <br />
  var FEED_URL = "http://10.0.8.50:9980/feeds/rss/mwsu.edu/news-feed-2/"; <br />
  $.ajax({ <br />
   url : FEED_URL, <br />
   type : "GET", <br />
   success : function(xml) { <br />
    var items = xml.getElementsByTagName('item'); <br />
    var item, title, desc, thumb, swf, i, l; <br />
    for(i=0, l < items.length; i < l; i++){ <br />
     item = items[i]; <br />
     title = item.getElementByTagName("title")[0].textContent; <br />
     link = item.getElementByTagName("link")[0].textContent; <br />
     $('#News').append('<li><a href="' + link + '">' + title + '</a></li>'); <br />
    } <br />
   } <br />
  }); <br />
 }); <br />
</script>

Hey Matt,

Can you confirm that the code above works as expected when directed to an XML RSS feed besides the one generated by CM1?

I’ve been trying to peice things from the web to make this work but can’t seem to get it to. I have saved a local copy of the Percussion XML file and it doesn’t work with it either.

So I have new code and tested it with a basic XML item. Below is the code that I’m using. When I place in the Percussion published XML link, it doesn’t work anymore.


  
<title>XML &amp; AJAX</title>   
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript"></script>   
<script type="text/javascript"> <br />
 $(document).ready(function(){
<br />
  $.ajax({ <br />
   type: "GET", <br />
   /* url: "NewsFeed.xml", */ <br />
   url: "http://10.0.8.10:9980/feeds/rss/mwsu.edu/news-feed-2/", <br />
   dataType: "xml", <br />
   success: function(xml) { <br />
    $(xml).find('item').each(function(){ <br />
     var title = $(this).find('title').text(); <br />
     var link = $(this).find('link').text(); <br />
     var date = $(this).find('pubDate').text(); <br />
     $('<li></li>').html('<a href="'+link+'">'+title+'</a>').appendTo("#news"); <br />
    }); <br />
   } <br />
  }); <br />
 }); <br />
</script>

Matt,

Your code looks good. The problem is that ajax doesn’t support cross domain requests for XML content, which is what you’re doing when you specify the IP address and port for your FEED_URL.

If you are looking to get the above code running on the same IIS server that your CM1 site is running off of, you can setup your IIS server to proxy the RSS feed connection from Tomcat through IIS, which would then allow you to use the FEED_URL of “/feeds/rss/mwsu.edu/news-feed-2/”.

I have tested such a configuration on my local machine using your code, and it works. If this setup would work for what you’re looking to do, we can get on a quick call so I can show you how to setup this proxy configuration in IIS. Let me know if this would help.

Nathaniel, that would be great if you could do that. I would really appreciate it.

Matt,

Sure, I’m going to open up a support ticket for us so we can setup a time to do this. Please check your inbox shortly.

Thanks to Nathaniel we got everything working. Below is the ULR Rewrite rules that we used in IIS.

Feed Services
Pattern: feeds(.*)
Rewrite URL: http://localhost:9980/feeds{R:1}

Dynamic Indexing Services
Pattern: perc-metadata-services(.*)
Rewrite URL: http://localhost:9980/perc-metadata-s…

Form Processing
Pattern: perc-form-processor(.*)
Rewrite URL: http://localhost:9980/perc-form-proce…

Comments and Likes
Pattern: perc-comments-services(.*)
Rewrite URL: http://localhost:9980/perc-comments-s…

Common UI
Pattern: perc-common-ui(.*)
Rewrite URL: http://localhost:9980/perc-common-ui{…

Membership Services
Pattern: perc-membership-sevices(.*)
Rewrite URL: http://localhost:9980/perc-membership…

Polls
Pattern: perc-polls-services(.*)
Rewrite URL: http://localhost:9980/perc-polls-serv…