Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/08/2008, 09:22
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: Me tira el cartel "Cargando" pero no me carga la pagina!

Tenés problemas con el llamado y los ámbitos (se genera una closure y no la estás resolviendo). Probá así:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>test closures</title>
<
html>
<
head>
<
script>
function 
Ajax()
{
    
//--------------------------
    // Variables
    //--------------------------
    
this.handler false//Objeto

    //--------------------------
    // Funciones
    //--------------------------
    
this.conectar = function()
    {
        if(
navigator.appName == "Microsoft Internet Explorer") {
            try {
                
this.handler = new ActiveXObject('Msxml2.XMLHTTP');
            } catch(
e) {
                try {
                    
this.handler = new ActiveXObject('Microsoft.XMLHTTP');
                } catch(
e) {}
            }
        } else {
            
this.handler = new XMLHttpRequest();
        }
    }
    var 
_this=this;//con esto solucionás el tema del scope
    
this.estados = function()
    {
    
        if(
_this.handler.readyState == 1) {
            
document.getElementById('estado').innerHTML "Cargando...";
        } else if (
_this.handler.readyState == 4) {
            
document.getElementById('estado').innerHTML "Finalizado...";
            
document.getElementById('carga').innerHTML _this.handler.responseText;
        }
    }
    
    
this.enviar = function(urlmetodovalores)
    {
        
this.handler.open(metodourltrue);
        
this.handler.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        
this.handler.onreadystatechange this.estados;
        
        if(
metodo.toUpperCase() == 'POST') {
            
this.handler.send(valores);
        } else {
            
this.handler.send(null);
        }
    }
}

window.onload = function()
{
    
pagina = new Ajax();
    
pagina.conectar();
    
pagina.enviar('prueba.php''GET');
}
</script>
</head>

<body>
<div id="estado">En espera</div>
<div id="carga">Vacio</div>
</body>
</html> 
Edito: ups, se me adelantó GatorV, pero bueno, sin resolver la closure tampoco te habría funcionado ;)

Última edición por Panino5001; 08/08/2008 a las 09:27