Ver Mensaje Individual
  #5 (permalink)  
Antiguo 27/02/2009, 11:05
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Fallo al cargar XML desde javascript

No vi lo de ajax. Lo que posteé antes funciona correctamente (lo testeé antes de responderte). Fijate que el xml generado por php tenga los headers que correspondan y no haya errores de parseo. También estar testeándolo en un servidor web. Te dejo mis testeos para que veas:
Código PHP:
<?php 
ob_start
();
header("Content-type:text/xml");
echo 
'<';
?>
?xml version="1.0" encoding="utf-8" ?>
    <provincia>
        <nombre>Gerona</nombre>
        <idprovincia>1</idprovincia>
        <localidad>Ripoll</localidad>
    </provincia>
<?php ob_end_flush(); ?>
Código javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Documento sin t&iacute;tulo</title>
  6. </head>
  7.  
  8. <body>
  9. <script>
  10. function importaXML(archivo)
  11. {
  12. var xmlDoc;
  13. // code for IE
  14. if (window.ActiveXObject)
  15.   {
  16.   xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  17.   }
  18. // code for Mozilla, Firefox, Opera, etc.
  19. else if (document.implementation && document.implementation.createDocument)
  20.   {
  21.   xmlDoc=document.implementation.createDocument("","",null);
  22.   }
  23. else
  24.   {
  25.   alert('Tu navegador no puede manejar este script');
  26.   }
  27. xmlDoc.async=false;
  28. xmlDoc.load(archivo);
  29. return(xmlDoc);
  30. }
  31.  
  32. function mostrarInfo(){
  33.     xmlDoc=importaXML("test.php");
  34.     var x = xmlDoc.getElementsByTagName("provincia")[0];
  35.     alert(x.getElementsByTagName('nombre')[0].firstChild.data);
  36. }
  37. mostrarInfo()
  38. </script>
  39. </body>
  40. </html>