Ver Mensaje Individual
  #7 (permalink)  
Antiguo 08/08/2008, 14:45
Avatar de MaBoRaK
MaBoRaK
 
Fecha de Ingreso: abril-2003
Ubicación: La Paz - Bolivia
Mensajes: 2.003
Antigüedad: 21 años
Puntos: 35
Respuesta: Me tira el cartel "Cargando" pero no me carga la pagina!

loading...............

Bueno aplicando esto tambien se podría encapsular TODOS los metodos de una clase.
Código PHP:
          var argumentsToArray=function(a){
                 var 
args=[];
                for(var 
i=0;i<a.length;i++){args.push(a[i]);};
                 return 
args;
         };


        
Object.prototype.isObjectStrict = function()
         {
               return (
this.appendChild)?false:true;
         };
         
/**
        * es| Expandir una Clase dentro de sus objetos literales
        * @param {Object}
        */
        
Object.prototype.expand=function(Class,recursive)
        {
                Class=Class || 
this;
                for(var 
i in this)
                {
                        if(
this.propertyIsEnumerable(i) && (typeof this[i]==="function" || (recursive===true && typeof this[i]==="object" && this[i].isObjectStrict())))
                        {
                                try{
                                        if(
typeof this[i]==="function")
                                        {
                                                
//kkk.push(this[i]);
                                                
this[i]=this[i].extend(Class);
                                        }
                                        else
                                        {
                                                
this[i]=this[i].expand(Class,recursive);
                                        }
                                }
                                catch(
e){
                                        
this[i]=this[i];
                                }
                        }
                        else
                        {
                                
//alert(i);
                        
}
                }
                return 
this;
        };
        Function.
prototype.isObject     false;
        Function.
prototype.isArray      false;
        
/**
        * es| Expandir función en una Clase
        * @param {Funcion}
        */
        
Function.prototype.extend=function(Class)
        {
                try{
                        var 
oThis=this;
                        var 
args=argumentsToArray(arguments);
                        
args.splice(0,1);
                        return function()
                        {
                                return 
oThis.apply(Class,argumentsToArray(arguments).concat(args));
                        };
                }
                catch(
e){
                        return 
this;
                }
        };
        
/**
        * es| Añadir argumentos a una función
        * @param {Function}
        */
        
Function.prototype.args=function()
        {
                var 
oThis=this;
                var 
args=argumentsToArray(arguments);
                return function()
                {
                        return 
oThis.apply(oThis,argumentsToArray(arguments).concat(args));
                };
        }; 
Código:
function Ajax()
{
    //--------------------------
    // Variables
    //--------------------------
    this.handler = false; //Objeto

    //--------------------------
    // Funciones
    //--------------------------
    this.conectar = function()
    {
    }
    this.estados = function()
    {
    }
    
    this.enviar = function(url, metodo, valores)
    {
        this.handler.open(metodo, url, true);
        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);
        }
    }
    this.expand(this);
    return this;
}

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>
De esta forma como dije, todos los métodos de la clase ya vienen ENCERRADAS.

TODO EN UNO

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>
          var 
argumentsToArray=function(a){
                 var 
args=[];
                for(var 
i=0;i<a.length;i++){args.push(a[i]);};
                 return 
args;
         };


        
Object.prototype.isObjectStrict = function()
         {
               return (
this.appendChild)?false:true;
         };
         
/**
        * es| Expandir una Clase dentro de sus objetos literales
        * @param {Object}
        */
        
Object.prototype.expand=function(Class,recursive)
        {
                Class=Class || 
this;
                for(var 
i in this)
                {
                        if(
this.propertyIsEnumerable(i) && (typeof this[i]==="function" || (recursive===true && typeof this[i]==="object" && this[i].isObjectStrict())))
                        {
                                try{
                                        if(
typeof this[i]==="function")
                                        {
                                                
//kkk.push(this[i]);
                                                
this[i]=this[i].extend(Class);
                                        }
                                        else
                                        {
                                                
this[i]=this[i].expand(Class,recursive);
                                        }
                                }
                                catch(
e){
                                        
this[i]=this[i];
                                }
                        }
                        else
                        {
                                
//alert(i);
                        
}
                }
                return 
this;
        };
        Function.
prototype.isObject     false;
        Function.
prototype.isArray      false;
        
/**
        * es| Expandir función en una Clase
        * @param {Funcion}
        */
        
Function.prototype.extend=function(Class)
        {
                try{
                        var 
oThis=this;
                        var 
args=argumentsToArray(arguments);
                        
args.splice(0,1);
                        return function()
                        {
                                return 
oThis.apply(Class,argumentsToArray(arguments).concat(args));
                        };
                }
                catch(
e){
                        return 
this;
                }
        };
        
/**
        * es| Añadir argumentos a una función
        * @param {Function}
        */
        
Function.prototype.args=function()
        {
                var 
oThis=this;
                var 
args=argumentsToArray(arguments);
                return function()
                {
                        return 
oThis.apply(oThis,argumentsToArray(arguments).concat(args));
                };
        };
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();
        }
    }
    
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);
        }
    };
    
this.expand(this);
    return 
this;
}

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> 
connection closed.
__________________

Maborak Technologies