In this example I will show you how to easily load RSS Feeds into your web site by using Ajax. Of course you can load Rss Feeds directly in your Php script, but an Ajax request won’t slow down the loading process. However for security reasons, Ajax cannot make remote/external calls to XML. Therefore you have to create a bridge in Php, that accesses the Feeds and returns the XML locally. Anyways here’s how to get your Twitter feeds- but of course you can apply this code to any other XML file.
Here’s the bridge.php file:
header("Content-Type: application/xml; charset=UTF-8");
$feed = (isset($_REQUEST['feed'])) ? $_REQUEST['feed'] : '';
if(!empty($feed) || is_string($feed)) echo file_get_contents("http://".$feed);
?>
Ajax Request:
jQuery("#loading").show();
jQuery.ajax({
type: "GET",
url: "bridge.php?feed="+escape("twitter.com/statuses/user_timeline/55789790.rss"),
dataType: "xml",
success: parseXml
});
function parseXml(xml) {
var items = xml.getElementsByTagName('item');
$("lasttweet").set("html",items[0].getElementsByTagName('description')[0].firstChild.nodeValue);
}
});
Posted in jQuery | Trackback Url








No Responses to “Ajax Request for RSS Feeds with jQuery”
Trackbacks/Pingbacks
Leave a reply