Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/09/2007, 15:34
israbart
 
Fecha de Ingreso: septiembre-2007
Mensajes: 76
Antigüedad: 16 años, 7 meses
Puntos: 2
problemas con responseXML

Soy principiante en esto del Ajax y tengo un pequeño problema. Al momento de recibir la respuesta de la pagina que mando a llamar con el Ajax, me marca un error. Me marca que la pagina no tiene propiedades, ya revise varios foros y varias soluciones, pero no consigo hacer que funcione. Este es el codigo

Este es buscar.php
<?
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Oct 1997 05:00:00 GMT");

echo '
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<pagina>
<campo1>Juan</campo1>
<campo2>Pedro</campo2>
<campo3>LIly</campo3>
</pagina>';
?>

y este es la funcion donde la llamo

<script type="text/javascript">
function ajax()
{
var xmlHttp = false;
if(typeof(XMLHttpRequest) != 'undefined')
{
try{
xmlHttp = new XMLHttpRequest();
}
catch(e){}
}
else {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

var xmlHttp = ajax();

function buscar_p()
{
xmlHttp.open("GET", "buscar", true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
function updatePage()
{
if (xmlHttp.readyState == 4)
{
if(xmlHttp.status==200)
{
var pagina_p = xmlHttp.responseXML;
var nombres = pagina_p.getElementsByTagName("campo1")[0].childNodes[0].data;
// alert(nombres);
alert(pagina_p);
}

}
}
</script>

De esta manera me sale un alert que dice null y si habilito el alert('nombres') me marca el error que les habia comentado.
De antemano gracias por su pronta respuesta.