Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Ajax RSS reader help

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
racinnation
New one
New one


Joined: 04 Jul 2006
Posts: 2

PostPosted: Wed Jul 05, 2006 12:26 am    Post subject: Ajax RSS reader help Reply with quote

I found this simple rss reader widget online somewhere, it works great. I just need to know how to add more than one feed and rearrange the feeds in a table with 2 columns, one cell for each feed.

Code is below, any help would be greatly appreciated.

<html>

<head>
<title>AJAX RSS Reader</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<script language="javascript" type="text/javascript">

var RSSRequestObject = false; // XMLHttpRequest Object
var Backend = 'http://www.phpmagazine.net/18_ajax/feeds/rss20'; // Backend url
window.setInterval("update_timer()", 1200000); // update the data every 20 mins


if (window.XMLHttpRequest) // try to create XMLHttpRequest
RSSRequestObject = new XMLHttpRequest();

if (window.ActiveXObject) // if ActiveXObject use the Microsoft.XMLHTTP
RSSRequestObject = new ActiveXObject("Microsoft.XMLHTTP");


/*
* onreadystatechange function
*/
function ReqChange() {

// If data received correctly
if (RSSRequestObject.readyState==4) {

// if data is valid
if (RSSRequestObject.responseText.indexOf('invalid') == -1)
{
// Parsing RSS
var node = RSSRequestObject.responseXML.documentElement;


// Get Channel information
var channel = node.getElementsByTagName('channel').item(0);
var title = channel.getElementsByTagName('title').item(0).firstChild.data;
var link = channel.getElementsByTagName('link').item(0).firstChild.data;

content = '<div class="channeltitle"><a href="'+link+'">'+title+'</a></div><ul>';

// Browse items
var items = channel.getElementsByTagName('item');
for (var n=0; n < items.length; n++)
{
var itemTitle = items[n].getElementsByTagName('title').item(0).firstChild.data;
var itemLink = items[n].getElementsByTagName('link').item(0).firstChild.data;
try
{
var itemPubDate = '<font color=gray>['+items[n].getElementsByTagName('pubDate').item(0).firstChild.data+'] ';
}
catch (e)
{
var itemPubDate = '';
}


content += '<li>'+itemPubDate+'</font><a href="'+itemLink+'">'+itemTitle+'</a></li>';
}


content += '</ul>';
// Display the result
document.getElementById("ajaxreader").innerHTML = content;

// Tell the reader the everything is done
document.getElementById("status").innerHTML = "Done.";

}
else {
// Tell the reader that there was error requesting data
document.getElementById("status").innerHTML = "<div class=error>Error requesting data.<div>";
}

HideShow('status');
}

}

/*
* Main AJAX RSS reader request
*/
function RSSRequest() {

// change the status to requesting data
HideShow('status');
document.getElementById("status").innerHTML = "Requesting data ...";

// Prepare the request
RSSRequestObject.open("GET", Backend , true);
// Set the onreadystatechange function
RSSRequestObject.onreadystatechange = ReqChange;
// Send
RSSRequestObject.send(null);
}

/*
* Timer
*/
function update_timer() {
RSSRequest();
}


function HideShow(id){
var el = GetObject(id);
if(el.style.display=="none")
el.style.display='';
else
el.style.display='none';
}

function GetObject(id){
var el = document.getElementById(id);
return(el);
}

</script>

<body onload="RSSRequest();">

<h2>AJAX RSS Reader</h2>
<div id="status" style="display:none"></div>
<div id="ajaxreader"></div>
</body>

</html>
_________________
Breaking NASCAR News: www.racinnation.com
Back to top
View user's profile Send private message Visit poster's website
deejay
Forum Assistant
Forum Assistant


Joined: 17 May 2006
Posts: 78
Location: Netherlands

PostPosted: Thu Jul 06, 2006 7:08 am    Post subject: hi Reply with quote

hi,

i tested this example but it doesn't seem to work (tested with ie 6 + firefox 1.0), where did you get this example ? (is it the one from phpmagazine ?)

why not use this one, it already has the functions that you talk about.
http://www-128.ibm.com/developerworks/xml/library/x-ajaxrss/

it has a mysql backend.

bye, dj
_________________
please correct me if i am wrong
seo-expertglobalwarming
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
racinnation
New one
New one


Joined: 04 Jul 2006
Posts: 2

PostPosted: Sat Jul 08, 2006 5:41 pm    Post subject: Reply with quote

I briefly tried to get the IBM script to work and couldnt and I would rather have a lightweight script with no DB interaction if possible.

I think the one I have may be the phpmag example, not really sure it's been a while since I tracked it down.

Can I even do what I want to do without the use of a DB?
_________________
Breaking NASCAR News: www.racinnation.com
Back to top
View user's profile Send private message Visit poster's website
deejay
Forum Assistant
Forum Assistant


Joined: 17 May 2006
Posts: 78
Location: Netherlands

PostPosted: Mon Jul 10, 2006 8:19 am    Post subject: No problem Reply with quote

Hi raccination,

Shouldn't be a problem.

There is no need for data to be saved somewhere on the server as the list of xml feeds can be stored in an array clientside.


Ciao, DJ Cool
_________________
please correct me if i am wrong
seo-expertglobalwarming
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert