PHP and Ajax create advanced RSS aggregators

Source: Internet
Author: User

RSS aggregators are an exceptionally good application for building with a standard AJAX engine, but it is often difficult to implement a Cross-domain Ajax request for RSS feeds. In this article, I'll show you how to use a simple PHP function to implement the "bridging" Ajax engine and RSS content.
First, the introduction

Now, developing an RSS aggregator is no longer a difficult task, but developing a high-quality RSS aggregator is still quite difficult. On the other hand, creating a custom aggregator is generally not difficult, and within this aggregator you can provide an interface of your choice. RSS aggregation represents a class of data that is particularly suited to the consumption of an AJAX application because it is XML formatted and Ajax is able to display new feedback well without having to refresh the page. However, the problem always exists: it is impossible to implement Cross-domain AJAX requests in a standard AJAX engine. In this article, I'll show you how to use a very simple PHP function to bridge the AJAX engine and remote content (which in this article refers to RSS feeds).

"Hint" This article assumes that you have a basic understanding of PHP and have experience using AJAX and parsing XML. To fully understand the examples provided in this article, you need to download the corresponding source files.

Second, start

Before we begin formally, I would like to briefly describe the Ajax engine we will use to make the request. The engine simplifies Ajax invocation and helps to eliminate the large amount of redundancy that exists when the request is made and the response is dispatched. I'm not going to go into the details of its constituent code, but just to give you a brief introduction to how we use it in this article.

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

<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 import the JavaScript file, we can send a request by writing code similar to the following:

Ajaxupdater.update (' Get ', ' url ', callbackmethod); " >

The Ajaxupdater is an object that handles our Ajax calls. We simply call its Update method and pass the requested method, the URL we request, and the callback method we want to delegate the response to.

That's all we need to be concerned about when we make a request. Now, let's focus on customizing the RSS aggregator's capabilities.

Third, entry point

The entry point to the aggregator is the index.html file, which we call from the browser. Here is the code that describes the index:

<title>rss Aggregation with PHP and ajax</title>
<link href= "Css/layout.css" rel= "stylesheet" type= "Text/css"/>
<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>
<script type= "Text/javascript" src= "Js/controller/aggregator.js" ></script>
<script type= "Text/javascript" src= "Js/view/feed.js" ></script>
<body>

<div id= "Aggregator" >
<form name= "Feedform" method= "post" action= "javascript:AjaxUpdater.Update" (' Get ', ' bridge/rss.php?feed= ' Document.feedForm.feed.value, Aggregator.read); " >
<div class= "Header" >
<input type= "text" name= "feed" id= "feed" size= "M" >
<input type= "Submit" name= "Submit" value= "Add Feed" >

</div>
</form>
<div class= "Leftcolumn" >
<div id= "Titles" ></div>
<div id= "Loading" ></div>
</div>
<div class= "Rightcolumn" >
<div id= "description" ></div>
</div>

</div>

</body>

This file is responsible for importing CSS files that handle our aggregator display and all JavaScript files for creating the aggregator and making Ajax requests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.