How to Create Remote Ajax Requests / Page 3 | WebReference

How to Create Remote Ajax Requests / Page 3


How to Create Remote Ajax Requests [con't]

Accessing the Remote File

So, how do we reach the remote RSS feed? If you look at the index file you'll see that we are calling bridge.php and passing a feed parameter. The bridge.php file uses a method called file_get_contents, which takes the feed value, retrieves the file from the other server and writes it to the page to act as a response to the request. We also add a header to ensure that the file is returned as valid XML. That's it, but remember it's your job to make sure that these remote files are safe, all this method does is get what a user asks for and unfortunately we can't always trust our users.

Adding a Little Style

We finally have all of the functionality set, now we need to style the interface a bit. I'm keeping this simple, so please take the liberty to enhance your interface as you see fit.

What Now?

The objective of this article is not only about creating an Ajax-enabled RSS Aggregator, but is about making remote Ajax requests with PHP. PHP is a great partner with Ajax, as are many other server-side languages, so take a look around, read the APIs and I'm sure you'll discover something that you want to use.

About the Author

Kris Hadlock is the owner/founder of a Web design and development firm. He is the author of Ajax for Web Application Developers and has been a feature writer for numerous Web sites and design magazines. To learn more about Kris, visit or his blog at

Original: March 28, 2007

Digg This Add to