Home > Articles > Programming > Java

RSS Aggregation with PHP and AJAX

  • Print
  • + Share This
An RSS aggregator is the perfect application to build with a standard AJAX engine, but cross-domain AJAX requests to RSS feeds are not possible. In this article, Kris Hadlock shows how to leverage a simple PHP function to bridge the gap between the AJAX engine and RSS content.
Like this article? We recommend

Like this article? We recommend

RSS aggregators are not very hard to come by these days, but finding a good one can be quite difficult. On the other hand, creating a custom aggregator isn’t very difficult and can provide you with an interface of your own choosing. RSS aggregation presents the kind of data that’s perfect for being consumed by an AJAX application because of the simple fact that it’s XML, and AJAX can gracefully display new feeds without refreshing the page. The issue has always been that cross-domain AJAX requests are impossible with a standard AJAX engine. In this article, I’ll show you how to leverage a very simple PHP function to bridge the gap between the AJAX engine and the remote content, which in this case will be RSS feeds.

Getting Started

Before we get started, I want to briefly cover the AJAX engine that we’ll be using to make our requests. The engine simplifies AJAX calls and eliminates a lot of the redundancies that occur when making requests and delegating responses. I won’t go into the code that makes it function, but will give you a brief overview of how we’re using it in this article.

First, we’ll need to import all of the JavaScript files that make up the engine. The code, contained in our index.html file, looks like this:

<script type="text/javascript" src="js/model/HTTP.js"></script>
<script type="text/javascript" src="js/model/Ajax.js"></script>
<script type="text/javascript" src="js/model/AjaxUpdater.js"></script>

Once we have the JavaScript files imported, we can make a request simply by writing code similar to the following:

AjaxUpdater.Update(’GET’, ’url’, callbackMethod);">

The AjaxUpdater is an object that will handle our AJAX call. We simply call its update method and pass the method of the request, the URL that we’re requesting, and the callback method to which we want to delegate the response.

This is all we have to worry about when making our requests; now we can focus on the custom RSS aggregator functionality.

  • + Share This
  • 🔖 Save To Your Account