Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/02/2009, 10:10
jemarquesini
 
Fecha de Ingreso: noviembre-2006
Mensajes: 102
Antigüedad: 17 años, 6 meses
Puntos: 1
Respuesta: Fallo al cargar XML desde javascript

Gracias por la respuesta, Panino, pero no se soluciona el error así, ya que el fallo es que "x is undefined", luego cualquier cosa que aplique a esa variable simplemente no funcionará.

No obstante, ahora estoy usando ajax para descargar el archivo, pero sigue sin funcionar, dando otro error, que tambien me ocurrió anteriormente. El codigo es el siguiente:

Código PHP:
var peticion_ajax;

function 
descargaArchivo(url,funcion) { //funcion que se llamara onreadystatechange 
    // Obtener la instancia del objeto XMLHttpRequest
    
peticion_ajax inicializa_xhr();
    
    
// Preparar la funcion de respuesta
    
peticion_ajax.onreadystatechange funcion;
    
    
// Realizar peticion HTTP
    
peticion_ajax.open('GET'urltrue);
    
peticion_ajax.send(null);
}

function 
inicializa_xhr() {
    var 
objXML;
    
    try{
         
objXML = new ActiveXObject('Msxml2.XMLHTTP');
    }catch (
e1){
        try{
            
objXML = new ActiveXObject('Microsoft.XMLHTTP');
        }catch (
e2){
            
objXML false;
        }
    }
    
    if (
window.XMLHttpRequest)
        
objXML = new XMLHttpRequest();
    
    if (!
objXML && (typeof XMLHttpRequest != 'undefined'))
        
objXML = new XMLHttpRequest();
    return 
objXML;
}

function 
muestraInfo(){
    if(
peticion_ajax.readyState == && (peticion_ajax.status == 200 || window.location.href.indexOf("http")==-1)){
        var 
peticion_ajax.getElementsByTagName("provincia")[0];
        
alert(x.getElementsByTagName("nombre")[0].firstChild.nodeValue);
    }

El archivo xml es el mismo, luego haciendo descargaArchivo("query.php",muestraInfo) deberia aparecer un alert que dijese "Gerona". Sin embargo el error es "peticion_ajax.getElementsByTagName is not a function".

Este error ya me dio antes usando el otro metodo, pero no consigo hacer que funcione, ya que no logro saber donde esta el error.