PDA

View Full Version : Ajax.PeriodicalUpdater



spenoir
Jun 1st, 2007, 10:31 AM
Can anyone help me with this Prototype Ajax.PeriodicalUpdater function. At the moment it prints out the entire xml at the top of the 'data' div and then my parsing prints out repeatedly beneath it.

I'd like it to just display my parsed nodes and replace the html after each request.

I hope that makes sense. Try it for yourself it should work if you have prototype. I think there's a few things wrong with this code so any suggestions would be much appreciated.


function ajaxcall () {
var pars = $("rssfeed").serialize();



new Ajax.PeriodicalUpdater('data','rssget.php?id=BBC&cachetime=10',
{
method:'get',
parameters: pars,
//insertion: Insertion.Top,
frequency: 5,
decay: 2,
onSuccess:
//Parse returned XML
function (req){

var channel = req.responseXML.getElementsByTagName('channel');
var rssitem = req.responseXML.getElementsByTagName('item');


if (!req.responseXML.documentElement && req.responseStream) {
req.responseXML.load(req.responseStream);
}
for (var i=0;i< channel.length;i++)
{

var desc = getNodeValue(rssitem[i], 'description');
var itemtitledata = desc.split(':');
//alert(itemtitledata[0]+"__"+itemtitledata[1]);

var weatherImg = itemtitledata[1].slice(0,12);
alert(weatherImg);


var x = document.createElement('div');
x.className = 'holder';
var y = document.createElement('h1');
y.appendChild(document.createTextNode(getNodeValue(channel[i],'title')));
x.appendChild(y);
var z = document.createElement('p');
z.className = 'text';
z.appendChild(document.createTextNode(getNodeValue(rssitem[i],'description')));
x.appendChild(z);
var b = document.createElement('p');
b.className = 'published';
b.appendChild(document.createTextNode(getNodeValue(rssitem[i],'pubDate')));
x.appendChild(b);

if (weatherImg = "light showe") {
var a = document.createElement('img');
a.src = "images/lightshowers.gif";
x.appendChild(a);
}

document.getElementById('container').appendChild(x);
}
},
onFailure: function(){ alert('There is a problem with your XML request, please check file path\'s are correct') }
});

}

shyam
Jun 1st, 2007, 03:34 PM
change 'data' to an id thats not present in the document


new Ajax.PeriodicalUpdater('data','rssget.php?id=BBC&cachetime=10', {...});