Knowledge Base Nr: 00270 ajax7.txt - http://www.swe-kaiser.de

Downloads:

Ajax: Newsfeeder zyklisch auslesen und anzeigen (XML, XSLT, HTTPRequest - Auswerten mit XML-Funktionen)

  
<head>
<title>Nachrichten</title>

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

<script type="text/javascript">

var sID = "newsticker";
var urlFeed = 'k_getURL.php3?url=http://www.spiegel.de/schlagzeilen/rss/0,5291,20,00.xml&ctype=text/xml';

function loadNews()
{
var oXmlHttp = zXmlHttp.createRequest();
oXmlHttp.open("get", encodeURI(urlFeed), true);

oXmlHttp.onreadystatechange = function ()
{
if (oXmlHttp.readyState == 4)
{
if (oXmlHttp.status == 200)
{
var oXmlDom = zXmlDom.createDocument();
oXmlDom.async = false;
oXmlDom.loadXML(oXmlHttp.responseText);

var oXslDom = zXmlDom.createDocument();
oXslDom.async = false;
oXslDom.load("k_newsticker.xsl");

var str = zXslt.transformToText(oXmlDom, oXslDom);
if (str == "") //falls xslt nicht funktioniert hat von hand zusammenbasteln
{
var news = oXmlDom.getElementsByTagName("item");

for (n=0; n<news.length; n++)
{
var titles = news[n].getElementsByTagName("title");
var links = news[n].getElementsByTagName("link");

str += '<a target="news" href="' + links[0].text + '">' + titles[0].text + '</a><br />\n';
}
}

var newsBox = document.getElementById(sID);
newsBox.innerHTML = str;

setTimeout(loadNews, 5*60*1000); //alle 5 minuten updaten
}
}
};
oXmlHttp.send(null);
}

window.onload = function ()
{
if (zXmlHttp.isSupported())
{
loadNews();
}
}

</script>

</head>

<body">

<h2>Spiegel-Nachrichten (News-Feed Update alle 5 Minuten)</h2>
<span id="newsticker"></span>

</body>
</html>