Ver Mensaje Individual
  #15 (permalink)  
Antiguo 11/03/2008, 10:13
Avatar de mgusdl
mgusdl
 
Fecha de Ingreso: abril-2007
Ubicación: Malaga, España
Mensajes: 190
Antigüedad: 17 años
Puntos: 5
Re: responseXML.documentElement no funciona en IE

Buenas, resucito este tema porque no encuentro solución y aquí por lo menos está el problema enfocado.

La cosa es que he probado en Safari para windows, Netscape 9, Opera 9 y Firefox 2.0.0.12 y funciona correctamente, pero en IE7 no :(

Os pongo el codigo a ver que opinais:

JS-> Creacion del objeto XML (funciona):
Código PHP:
function xmlobj(){
    if (
window.XMLHttpRequest) return new XMLHttpRequest();
    else if (
window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
    else 
alert('No se pudo crear el objeto XML');
    } 
JS -> Llamando al archivo (en rojo donde peta en IE)
Código PHP:
function mifuncion(id) {
    
cont document.getElementById('micontenedor');
    
cutChilds(cont); // Limpiar primero
    
xo xmlobj();
    
xo.open('GET''xml/xml_miarchivo.php?id=' id);
    
xo.onreadystatechange = function() {
      if (
xo.readyState == 4) {
      [
COLOR="Red"]var obj  xo.responseXML.documentElement;[/COLOR]
      if (
obj.getElementsByTagName('individuo').length 0) {
        for (
i=0i<obj.getElementsByTagName('individuo').lengthi++) {
          
tr document.createElement('tr');
          
td document.createElement('td');
          
td.appendChild(document.createTextNode(itm.getElementsByTagName('id')[0].firstChild.data));
          
tr.appendChild(td);
          
td document.createElement('td');
          
td.appendChild(document.createTextNode(itm.getElementsByTagName('nombre')[0].firstChild.data));
          
tr.appendChild(td);
          
cont.appendChild(tr);
          }
        }
      }
    }
    
xo.send('');
        } 
PHP -> Creacion del XML
Código PHP:
<?php
require "session.php";
require 
"config.php";
require 
"funciones.php";
header ("Content-type: text/xml; charset=ISO-8859-1");
$id intval($_GET['id']);
if (
$id == 0) die("Datos de entrada no validos");

echo 
"\n<respuesta>";

$sql "SELECT * FROM mitabla m WHERE id=$id"

$q mysql_query($sql) or die("\n\t<error>ERROR DE MySQL!!</error>\n</respuesta>");
$f mysql_num_fields($q);
if (
mysql_num_rows($q) == 0) echo "\n\t<error>No se devolvieron resultados</error>";
else while (
$a mysql_fetch_array($q)) {
    
$telefono $a['C_tel'];
    if (!
$a['C_tel']) $telefono " ";
    
$email $a['C_email'];
    if (!
$a['C_email']) $email " ";
    echo 
"\n\t<individuo>";
    echo 
"\n\t\t<id>{$a['id']}</id>";
    echo 
"\n\t\t<nombre>{$a['Nombre']}</nombre>";
    echo 
"\n\t</individuo>";
    }
echo 
"\n</respuesta>";
?>
JS -> Bonus, funcion para eliminar todos los nodos hijo
Código PHP:
function cutChilds(node) {
    if (
node.hasChildNodes()) while (node.childNodes.length >= 1node.removeChild(node.firstChild);
    } 
Lo del charset ya lo he probado en utf8 y nada. Encima se ven mal algunos caracteres porque la codificacion del HTML es ISO

Última edición por mgusdl; 31/03/2008 a las 02:04 Razón: cambio etiquetas de codigo