I am learning to work with RSS and the truth is that I am very lost, I have this code but on the screen I only get "Loading Rss ..." but never upload anything. What is this about? What am I doing wrong?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ejemplo basico AJAX y XML</title>
<script type="text/javascript">
function cargar(){
var objHttp=null;
if(window.XMLHttpRequest) {
objHttp = new XMLHttpRequest();
} else if(window.ActiveXObject) {
objHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
objHttp.open("GET", "http://www.heraldo.es/index.php/mod.portadas/mem.rss" , true);
objHttp.onreadystatechange = function() {
if (objHttp.readyState == 4 && objHttp.status == 200) {
console.log(objHttp.responseXML);
var fichero = objHttp.responseXML; //recogemos el contenido
var noticias = fichero.documentElement;
//var noticias = fichero.getElementsByTagName("item");
var cadena = "";
for (i = 0;i < 3; i++){
cadena = cadena + "Titular: " + noticias.getElementsByTagName("item")[i].childNodes[1].firstChild.nodeValue + "<br/>";
cadena = cadena + "Descripcion: " + noticias.getElementsByTagName("item")[i].childNodes[9].firstChild.nodeValue + "<br/>";
cadena = cadena + "enlace <a href='" + noticias.getElementsByTagName("item")[i].childNodes[7].firstChild.nodeValue + "'> Link </a><br/><br/><br/>";
//cadena = cadena + "enlace "+ noticias.getElementsByTagName("link")[i].childNodes[0].firstChild.nodeValue + "<br/><br/><br/>";
}
alert(cadena);
document.getElementById("caja").innerHTML = cadena;
}
}
objHttp.send(null);
}
</script>
</head>
<body >
<div style="width:400px;height:400px; position:relative;" id="caja">
Cargando Rss...
</div>
<script>cargar();</script>
</div>
</body>
</html>
Cheers!