How to Create Remote Ajax Requests / Page 2 | WebReference

How to Create Remote Ajax Requests / Page 2

[previous] [next]

How to Create Remote Ajax Requests [con't]

Aggregating Feeds

The second JavaScript file, Aggregator, is the object that will receive the callback from the Ajax request in the index. It's Read method will get an XML response and parse the titles, links and items from the feed. It will then create an instance of a Feed object, which we'll create in a moment, based on the parameters that we pass to it. Once the feed is instantiated we push it into an array of feeds for later usage and fire the displayFeedTitles method. This method gets the title of the latest feed and displays it in the leftColumn, it then calls the DisplayTitles method, which iterates through all of the titles and adds them underneath the feed title. The last method, DisplayItem, will be called from the Feed object when a specific item from that feed is clicked on, it will then get the details from that item and display them to the user.

Creating a Feed Object

The final JavaScript file is a Feed object, which is constructed as a prototype. This object takes an id, title, _link and items, which are all passed to it from the Aggregators Read method. Upon instantiation a few properties are created and another method called parseItems is triggered. This method takes the items and iterates them, while accessing the linkTitle, the _link, the description and the guid. Each of the values are then placed into their own specific array to be used later when an item is clicked in the leftColumn. The other methods in this object are GetTitle, which is called from the Aggregator to get the title for the feed, GetAllTitles, which returns all of the item titles to the Aggregator to be displayed under the feed title and most importantly, the GetDetails method. The GetDetails method is where all of the content from a specific item are returned in a nice display that is rendered in the rightColumn. The details include the title, description, and most importantly a podcast player. The podcast player is from Odeo, a podcast service, and it takes the URL to the MP3 from the podcast in order to display a player to the user.

[previous] [next]