Ver Mensaje Individual
  #14 (permalink)  
Antiguo 11/08/2008, 09:22
Avatar de korg1988
korg1988
 
Fecha de Ingreso: junio-2006
Ubicación: Santa Fe, Argentina
Mensajes: 825
Antigüedad: 17 años, 10 meses
Puntos: 19
De acuerdo Alguien me ayuda a mejorar esto

HOla bueno abri este post poruqe el que tenia abierto antes se estaba haciendo medio largo y no daba para seguir preguntando! ya uqe habia solucionado mi problema!
el post es http://www.forosdelweb.com/f77/tira-...3/#post2525908

bueno, el codigo es el siguiente
No es mas que un simple Loader Ajax! pero bueno, quize armar mi propia class y hace poco que empece a crear mis propios objetos con javascript

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>

<
script>
function 
Ajax()
{
/*
*    Variables
*/
    
_this            =    this;
    
_this.Handler    =    false//Objeto
/*
* ESTADOS
*/
    
_this.Estados    =    new Object();
    
_this.Estados.Tipos =     new Array();
    
_this.Estados.Tipos['CARGANDO']    =    new Object();
    
_this.Estados.Tipos['COMPLETO']    =    new Object();
    
_this.Estados.Tipos['DESTINO']    =    new Object();
    
    
_this.Estados.Tipos['CARGANDO'].Value    =    1;
    
_this.Estados.Tipos['CARGANDO'].Msj        =    '';
    
_this.Estados.Tipos['CARGANDO'].ObjId    =    '';
    
    
_this.Estados.Tipos['COMPLETO'].Value    =    4;
    
_this.Estados.Tipos['COMPLETO'].Msj        =    '';
    
_this.Estados.Tipos['COMPLETO'].ObjId    =    '';
    
    
_this.Estados.Tipos['DESTINO'].ObjId    =    '';
    
/*
*    CONECTAR 'establece el objeto XMLHttpRequest'
*/
    
_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();
        }
    }
/*
*    CAMBIOS DE ESTADO 'acciones para onreadystatechange'
*/    
    
_this.Estados.Change = function()
    {
        if(
_this.Handler.readyState == _this.Estados.Tipos['CARGANDO'].Value) {
            
_this.Estados.Show(_this.Estados.Tipos['CARGANDO'].ObjId_this.Estados.Tipos['CARGANDO'].Msj);
        } else if(
_this.Handler.readyState == _this.Estados.Tipos['COMPLETO'].Value) {
            
_this.Estados.Show(_this.Estados.Tipos['COMPLETO'].ObjId_this.Estados.Tipos['COMPLETO'].Msj);
            
_this.Estados.Show(_this.Estados.Tipos['DESTINO'].ObjId_this.Handler.responseText);
        }
    }
/*
*    ENVIAR 'funcion estandar para envio de datos'
*/
    
_this.Enviar = function(urlmetodoparametros)
    {
        if(
_this.Handler == false) { _this.Conectar(); }    //Si no existe la conexion entonces la crea por unica vez
        
_this.Handler.open(metodourltrue);
        
_this.Handler.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        
_this.Handler.onreadystatechange _this.Estados.Change;
        
_this.Handler.send((metodo.toUpperCase() == 'POST') ? parametros null);
    }
    
    
_this.Estados.Show = function(objIdmsj)
    {
        
//segun el tipo de objeto decido entre usar innerHTML o value
        
if(document.getElementById(objId).tagName == 'DIV') {
            
document.getElementById(objId).innerHTML msj;
        }
        if(
document.getElementById(objId).tagName == 'INPUT') {
            
document.getElementById(objId).value msj;
        }
    }
    
    
//SETEAR LOS MENSAJES A MOSTRAR
    
_this.SetMsj = function(tipoEstadoobjIdmsj)
    {
        
_this.Estados.Tipos[tipoEstado].Msj msj;
        
_this.Estados.Tipos[tipoEstado].ObjId objId;
    }
    
_this.SetDestino = function(objId)
    {
        
_this.Estados.Tipos['DESTINO'].ObjId objId;    
    }
}

window.onload = function()
{
    
/*
    * IMPLEMENTACION
    */
    
pagina = new Ajax();
    
pagina.SetMsj('CARGANDO''estado''Cargando...');
    
pagina.SetMsj('COMPLETO''estado''Completado con Exito!!');
    
pagina.SetDestino('carga');
}
</script>
</head>

<body>
<input id="hola" onclick="pagina.Enviar('ejemplo.php', 'GET');" type="button" value="Cargar" />
<div id="estado">Sin acciones</div>
<div id="carga"></div>
</body>
</html> 
Bueno cualquier critica constructiva, y cualquier ayuda para aprender y mejorar mi codigo es aceptada!

Gracias desde ya!