...

View Full Version : Ajax.PeriodicalUpdater



spenoir
06-01-2007, 03:37 PM
Can anyone help me with this prototype Ajax.PeriodicalUpdater script. At the moment it just prints out the whole xml/rss document and prints my parsed xml beneath, when all i want it do is print out my parsed xml and replace it.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BBC RSS Weather reader</title>


<style type="text/css">

#data { border:1px solid red; }

</style>
<script type="text/javascript" src="prototype.js"></script>

<script type="text/javascript">

//Get xml node value
function getNodeValue(obj,tag)
{
return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}
//****************************************

function init () {
$('submit').onclick = function () {
ajaxcall();
}
}


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('data').appendChild(x);
}
},
onFailure: function(){ alert('There is a problem with your XML request, please check file path\'s are correct') }
});

}

</script>

</head>

<body>


<div id="widget">

<div id="container">
<div class="top">
<div id="inner">
<div id="content">

<form action="javascript: ajaxcall();" method="get" name="rssfeed" id="rssfeed">
<input class="" type="text" name="rss" id="rss" />
<input class="" type="image" name="submit" id="submit" />
</form>

<div id="data"></div>

</div>
</div>
</div>
</div>

</div>

</body>
</html>

spenoir
06-01-2007, 04:10 PM
ps. i've moved function init() below ajaxcall() to fix errors and also taken the action off the form. i've added body onload=init() too.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum