documentElement es nulo o no es un objeto
Publicado por Ricardo (3 intervenciones) el 02/02/2008 11:27:37
Cuando el servidor devuelve el XML desde JavaScript tengo una sentencia para que me coja el valor a partir de ese nodo:
x = xmlhttp.responseXML.documentElement.getElementsByTagName('registro');
sin embargo me sale el error siguiente:
"xmlhttp.responseXML.documentElement es nulo o no es un objeto"... no sé por qué me sale este mensaje por mucho que revise el código.
Alguien sabe el por qué de esto... gracias.
Codigo:
function loadXMLDoc(url){
xmlhttp=null;
if (window.XMLHttpRequest) {
// code for IE7, Firefox, Mozilla, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
// code for IE5, IE6
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null){
xmlhttp.onreadystatechange=onResponse;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}else{ alert("Your browser does not support XMLHTTP."); }
}
function onResponse(){
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200) {
alert("Problem retrieving XML data");
return;
}
txt="aaaaaaaaaaa<table border='1'>";
alert("ss221s");
alert("Totsal: " + xmlhttp.responseXML.documentElement.getElementsByTagName('registro').length);
x=xmlhttp.responseXML.getElementsByTagName('registro');
alert("Longitud: ");
for (i=0;i<x.length;i++){
txt=txt + "<tr>";
xx=x[i].childNodes;
for (j=0;j<xx.length;j++){
{
try{
txt= txt + "<td>" + xx[j].firstChild.nodeValue + "</td>";
}catch (er) { txt=txt + "<td> </td>"; }
}
}
txt=txt + "</tr>";
}
txt=txt + "</table>";
alert("Texto: " + txt);
document.getElementById('copy').innerHTML=txt;
}
</script>
x = xmlhttp.responseXML.documentElement.getElementsByTagName('registro');
sin embargo me sale el error siguiente:
"xmlhttp.responseXML.documentElement es nulo o no es un objeto"... no sé por qué me sale este mensaje por mucho que revise el código.
Alguien sabe el por qué de esto... gracias.
Codigo:
function loadXMLDoc(url){
xmlhttp=null;
if (window.XMLHttpRequest) {
// code for IE7, Firefox, Mozilla, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
// code for IE5, IE6
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null){
xmlhttp.onreadystatechange=onResponse;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}else{ alert("Your browser does not support XMLHTTP."); }
}
function onResponse(){
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200) {
alert("Problem retrieving XML data");
return;
}
txt="aaaaaaaaaaa<table border='1'>";
alert("ss221s");
alert("Totsal: " + xmlhttp.responseXML.documentElement.getElementsByTagName('registro').length);
x=xmlhttp.responseXML.getElementsByTagName('registro');
alert("Longitud: ");
for (i=0;i<x.length;i++){
txt=txt + "<tr>";
xx=x[i].childNodes;
for (j=0;j<xx.length;j++){
{
try{
txt= txt + "<td>" + xx[j].firstChild.nodeValue + "</td>";
}catch (er) { txt=txt + "<td> </td>"; }
}
}
txt=txt + "</tr>";
}
txt=txt + "</table>";
alert("Texto: " + txt);
document.getElementById('copy').innerHTML=txt;
}
</script>
Valora esta pregunta


0