Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Clase objAjax

Estas en el tema de Clase objAjax en el foro de Frameworks JS en Foros del Web. Buenas, hace 2 dias q decidí meterme de lleno en el mundo del Ajax, y la verdad es q me gusta mucho. He estado trasteando ...
  #1 (permalink)  
Antiguo 11/10/2005, 20:01
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
Clase objAjax

Buenas, hace 2 dias q decidí meterme de lleno en el mundo del Ajax, y la verdad es q me gusta mucho. He estado trasteando un poco y me he echo una clase en php llamada <b>objAjax</b>, cuya unica función es la de generar un objeto XMLHttpRequest(); y hacer un poco mas amigable su funcionamiento en php.

Esta muy verde y me gustaria q le echarais un ojo, la destriparais y me comentarais q os parece y si le falta algo.

Repito q es muuuuy simple, pero a mi me sirve y quizas os pueda servir a vosotros.

ajax.php
Código PHP:
<?

class objAjax
{
    var 
$url;
    var 
$codigo ="";
    var 
$entrada "";
    var 
$salida "";
    var 
$formato 'GET';
    
        
/********************************************************/
    /*    Constructor                                            */
    /*        - $entrada     --> Parametro de entrada            */
    /*        - $salida     --> Donde colocamos los datos        */
    /*        - $url     --> Url de donde cargamos datos            */
    /*        - $formato     --> GET o POST                        */
    /********************************************************/
    
function objAjax($entrada$salida,$url,$formato 'GET')
    { 
        
$this->url $url;
        
$this->entrada $entrada;
        
$this->formato $formato;
        
$this->Carga($salida);
    }
    
/********************************************************/
    /*    CreaCabecera                                        */
    /********************************************************/
    
function CreaCabecera()
    {
        
$this->codigo "<script>";
        
$this->codigo .= "function createRequestObject()\n";
        
$this->codigo .= "{\n";
        
$this->codigo .= "var request_;\n";
        
$this->codigo .= "var browser = navigator.appName;\n";
        
$this->codigo .= "if(browser == \"Microsoft Internet Explorer\"){\n";
        
$this->codigo .= "request_ = new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
        
$this->codigo .= "}else{\n";
        
$this->codigo .= "request_ = new XMLHttpRequest();\n";
        
$this->codigo .= "}\n";
        
$this->codigo .= "return request_;\n";
        
$this->codigo .= "}\n";
        
$this->codigo .= "var http = createRequestObject();\n";
        
$this->codigo .= "var url = '".$this->url."';\n";
    }

    
/********************************************************/
    /*    LeeDatos                                            */
    /********************************************************/
    
function LeeDatos()
    {
            
        if (
$this->formato == 'GET')
        {
            
$this->codigo .= "function getInfo(valor){\n";
            if (
$this->entrada != '')
                {
                
$this->codigo .= "valor = document.getElementById('".$this->entrada."').value;";
                
$this->codigo .= "    http.open('get', '".$this->url."?".$this->entrada."=' + valor);\n";
                }
            else
                
$this->codigo .= "    http.open('get', '".$this->url."' + valor);\n";
            
$this->codigo .= "    http.onreadystatechange = handleInfo;\n";
            
$this->codigo .= "    http.send(null);\n";
            
$this->codigo .= "}\n";
        }
        else
            {
            
$this->codigo .= "function getInfo(valor){\n";
            
$this->codigo .= "    http.open('POST', '".$this->url."',true);\n";
            
$this->codigo .= "    http.onreadystatechange = handleInfo;\n";
            
$this->codigo .= "    http.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");\n";
            if (
$this->entrada != '')
                {
                
$this->codigo .= "    valor = document.getElementById('".$this->entrada."').value;\n";
                
$this->codigo .= "    http.send('".$this->entrada."=' + valor);\n";
                }
            else
                
$this->codigo .= "    http.send(null);\n";
            
$this->codigo .= "}\n";
            }
    }
    
/********************************************************/
    /*    EscribeDatos                                        */
    /*        - $div     --> Donde volcamos los datos            */
    /********************************************************/
    
function EscribeDatos($div)
    {
        
/*Funcion q muestra el resultado*/
        
$this->codigo .= "function handleInfo(){\n";
        
$this->codigo .= "    if(http.readyState == 1){\n";
        
$this->codigo .= "        document.getElementById('".$div."').innerHTML = 'Me estoy cargando...';\n";
        
$this->codigo .= "    }\n";
        
$this->codigo .= "    if(http.readyState == 4){\n";
        
$this->codigo .= "        document.getElementById('".$div."').innerHTML = http.responseText;\n";
        
$this->codigo .= "    }\n";
        
$this->codigo .= "}\n";
    }

    
/********************************************************/
    /*    Carga                                                */
    /*        - $en     --> Donde volcamos los datos            */
    /********************************************************/
    
function Carga($en)
    {
        
$this->CreaCabecera();
        
$this->LeeDatos();
        
$this->EscribeDatos($en);
        
$this->codigo .= "</script>\n";
    }

    
/********************************************************/
    /*    Muestra                                                */
    /********************************************************/
    
function Muestra ()
    {
        return 
$this->codigo;
    }
}
index.php

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Primera Pagina con Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
.tNum
{
background-color:#FFFFCC;
width:100%;
border-style:solid;
border-width:thin;
text-align:center;
}
th
{
background-color:#FFCC00;
color:#000000;
}
.tdArt:hover
{
background-color:#FF3300;
color:#FFFFFF;
}
#my_div
{
background-color:#99CCFF;
border-style:dotted;
border-width:thin;
}
</style>
<?
include("ajax.php");

//Variables
$x=0;
$cols 15;

//Creamos el objeto $http
// id --> Es la ENTRADA
// my_div --> Es la Salida
// datos.php --> Es la URL de donde sacamos los datos.
// GET --> Es el FORMATO en que pasamos los datos. (POST/GET)
$http = new objAjax('id',"my_div","datos.php",'GET');
echo 
$http->Muestra();

?>
</head>
<body>
Numero de noticia: <input onKeyup="getInfo()" id="id"/>
<hr/>
<div id="my_div">
Haz click sobre algun numero de arriba.
</div>
</body>
</html>
datos.php
Código PHP:
<?php
// Utilizo una clase para conectar y operar con la BD, el objeto es $db.
include("connect.php"); //conectamos a la BD

//Recogemos el ID;
$id = (isset($_GET['id']))?$_GET['id']:$_POST['id'];

//realizamos la consulta
$result $db->query("    SELECT * FROM tabla WHERE ID='".$id."'");

$row $db->fetch_assoc($result);
echo 
"<h2>Estamos viendo la noticia: ".$id."</h3><br/>";
?>
<table width="100%" border="1">
    <tr>
        <th colspan="2"><?=$row[0]?></th>
    </tr>
    <tr>
      <td width="26%"><?=$row[1]?></td>
      <td width="74%"><?=$row[2]?> </td>
  </tr>
    <tr>
      <td colspan="2"><?=$row[3]?>&nbsp;</td>
  </tr>
    
</table>
Espero vuestros comentarios. Un saludo.

Podeis verlo funcionando: aqui
__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
  #2 (permalink)  
Antiguo 12/10/2005, 05:02
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Moví tu mensaje al foro de AJAX (con mención en el foro de PHP) para que te hagan los comentarios respectivos en el foro de AJAX.

Un saludo,
  #3 (permalink)  
Antiguo 12/10/2005, 05:06
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Una consulta ...

Esta classe si bien el ejemplo usa un objeto "DIV" .. podria ser aplicable a otro tipo de objetos por ejemplo de formulario como un "input" (text) sin cambios muy drásticos? ...

Me (supongo que "nos") gustaría ver algunas aplicaciones más de la classe (ejemplos) de uso que podríamos darle.

Un saludo,
  #4 (permalink)  
Antiguo 12/10/2005, 05:40
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
Si lo quieres en un textarea
http://www.symbianforever.com/ajax/ajax2/

<b>index.php</b>
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Primera Pagina con Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
.tNum
{
background-color:#FFFFCC;
width:100%;
border-style:solid;
border-width:thin;
text-align:center;
}
th
{
background-color:#FFCC00;
color:#000000;
}
.tdArt:hover
{
background-color:#FF3300;
color:#FFFFFF;
}
#titulo
{
background-color:#99CCFF;
border-style:dotted;
border-width:thin;
width:400px;
height:400px;
}
</style>
<?
include("ajax.php");

$http = new objAjax('id',"titulo","datos.php",'GET');
echo 
$http->Muestra();
?>
</head>
<body>
Numero de noticia: <input onKeyup="getInfo()" id="id"/>
<hr/>
<textarea id="titulo"></textarea>
</body>
</html>
<b>datos.php</b>

Código PHP:
<?php

include("connect.php");
$id = (isset($_GET['id']))?$_GET['id']:$_POST['id'];
$result $db->query("    SELECT ...."");
$row = $db->fetch_assoc($result);
?>
<?=$row[0]?>
Espero q os sirva.
__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
  #5 (permalink)  
Antiguo 12/10/2005, 05:48
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
Despues de probarlo, noto q en los textarea no refresca bien el contenido, y que muy feo.
Pero seguire indagando.
__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
  #6 (permalink)  
Antiguo 12/10/2005, 11:32
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Ok, gracias por el interes Spyn_ET

Un saludo,
  #7 (permalink)  
Antiguo 12/10/2005, 15:01
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Cita:
Iniciado por Spyn_ET
Despues de probarlo, noto q en los textarea no refresca bien el contenido, y que muy feo.
Pero seguire indagando.
Qué tal,

es porque a un campo de form no se le puede aplicar un innerHTML, debes trabajar cambiándole su value.

Pídele un document.getElementById('titulo').value= http.responseText;

Un saludo
  #8 (permalink)  
Antiguo 12/10/2005, 16:25
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
Muchas gracias, por la info!!!

Teneis alguna idea de como podria saber si un objeto es form o no? Es q he modificado la clase, y claro despues de esto tendre q volver a hacerlo. Y dependiendo del tipo de objeto q haya de modificar hacer un .value o un innerHTML.

Código PHP:
<?

class objAjax
{
    var 
$url;
    var 
$codigo ="";
    var 
$entrada "";
    var 
$salida "";
    var 
$formato 'GET';
    
    
/********************************************************/
    /*    Constructor                                            */
    /*        - $entrada     --> Parametro de entrada            */
    /*        - $salida     --> Donde colocamos los datos        */
    /*        - $url     --> Url de donde cargamos datos            */
    /*        - $formato     --> GET o POST                        */
    /********************************************************/
    
function objAjax($entrada$salida,$url,$formato 'GET')
    { 
        
$this->url $url;
        
$this->entrada $entrada;
        
$this->formato $formato;
        
$this->Carga($salida);
    }
    
/********************************************************/
    /*    CreaCabecera                                        */
    /********************************************************/
    
function CreaCabecera()
    {
        
$this->codigo "<script>";
        
$this->codigo .= "function createRequestObject()\n";
        
$this->codigo .= "{\n";
        
$this->codigo .= "var request_;\n";
        
$this->codigo .= "var browser = navigator.appName;\n";
        
$this->codigo .= "if(browser == \"Microsoft Internet Explorer\"){\n";
        
$this->codigo .= "request_ = new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
        
$this->codigo .= "}else{\n";
        
$this->codigo .= "request_ = new XMLHttpRequest();\n";
        
$this->codigo .= "}\n";
        
$this->codigo .= "return request_;\n";
        
$this->codigo .= "}\n";
                
$this->codigo .= "var http = createRequestObject();\n";
        
$this->codigo .= "var url = '".$this->url."';\n";
        
/*********************************************/
        
$this->codigo .= "// Funcion q reemplaza el texto\n";
        
$this->codigo .= "function replaceHTML(idName, content)\n";
        
$this->codigo .= "{\n";
        
$this->codigo .= "    var target = document.getElementById(idName); \n";   
        
$this->codigo .= "    target.innerHTML = content;\n"
        
$this->codigo .= "}\n";[/B]
        
/*********************************************/
    
}
    
/********************************************************/
    /*    LeeDatos                                            */
    /********************************************************/
    
function LeeDatos()
    {
            
        if (
$this->formato == 'GET')
        {
            
$this->codigo .= "function getInfo(valor){\n";
            if (
$this->entrada != '')
                {
                
$this->codigo .= "valor = document.getElementById('".$this->entrada."').value;";
                
$this->codigo .= "    http.open('get', '".$this->url."?".$this->entrada."=' + valor);\n";
                }
            else
                
$this->codigo .= "    http.open('get', '".$this->url."' + valor);\n";
            
$this->codigo .= "    http.onreadystatechange = handleInfo;\n";
            
$this->codigo .= "    http.send(null);\n";
            
$this->codigo .= "}\n";
        }
        else
            {
            
$this->codigo .= "function getInfo(valor){\n";
            
$this->codigo .= "    http.open('POST', '".$this->url."',true);\n";
            
$this->codigo .= "    http.onreadystatechange = handleInfo;\n";
            
$this->codigo .= "    http.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");\n";
            if (
$this->entrada != '')
                {
                
$this->codigo .= "    valor = document.getElementById('".$this->entrada."').value;\n";
                
$this->codigo .= "    http.send('".$this->entrada."=' + valor);\n";
                }
            else
                
$this->codigo .= "    http.send(null);\n";
            
$this->codigo .= "}\n";
            }
    }
    
/********************************************************/
    /*    EscribeDatos                                        */
    /*        - $div     --> Donde volcamos los datos            */
    /********************************************************/
    
function EscribeDatos($div)
    {
        
/*Funcion q muestra el resultado*/
        
$this->codigo .= "function handleInfo(){\n";
        
$this->codigo .= "    if(http.readyState == 1){\n";
        
$this->codigo .= "        replaceHTML('".$div."', 'Me estoy cargando...');\n";
        
$this->codigo .= "    }\n";
        
$this->codigo .= "    if(http.readyState == 4){\n";
        
$this->codigo .= "        replaceHTML('".$div."', http.responseText);\n";
        
$this->codigo .= "    }\n";
        
$this->codigo .= "}\n";
    }

    
/********************************************************/
    /*    Carga                                                */
    /*        - $en     --> Donde volcamos los datos            */
    /********************************************************/
    
function Carga($en)
    {
        
$this->CreaCabecera();
        
$this->LeeDatos();
        
$this->EscribeDatos($en);
        
$this->codigo .= "</script>\n";
    }

    
/********************************************************/
    /*    Muestra                                                */
    /********************************************************/
    
function Muestra ()
    {
        return 
$this->codigo;
    }
}
__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
  #9 (permalink)  
Antiguo 12/10/2005, 17:29
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Hum .. digamos que para averiguarlo automáticamente habría que contemplar tantas posibilidades que resultaría casi absurdo.

El tema es el siguiente, el único dato del objeto con el que se va a trabajar es el id y con eso no se puede saber qué tipo de objeto es. No existe (que yo sepa) una propiedad que contemple si es o no un campo de form. Todo lo más sería pedirle su tagName y pasearlo por un condicional que averigue si coincide con un listado de posibilidades pero me parece que el hacerlo así no tiene mucho sentido.

En tu lugar lo que haría sería simplemente agregar un argumento más a pasarle a la clase php con un simple true o false y que la clase escriba una u otra línea a la función js. Claro que esto funcionaría sólo con un tipo de campos dentro de un mismo documento; si quisieras poder usarlo tanto para controles de formularios como para otro tipo de elementos en el mismo documento entonces se podría agregar el enviar también ese parámetro a true o false al llamar a la propia función javascript.


Por un lado, prueba a ponerle esto a tu clase en la función CambiaCabecera()
Código:
        /*********************************************/ 
        $this->codigo .= "// Funcion q reemplaza el texto\n"; 
        $this->codigo .= "function replaceHTML(idName, content,esValue)\n"; 
        $this->codigo .= "{\n"; 
        $this->codigo .= "    var target = document.getElementById(idName); \n"; 
    $this->codigo .= "    propiedad = esValue ? 'value' : 'innerHTML'; \n";   
        $this->codigo .= "    eval('target.' + propiedad + ' = content;') \n"; 
        $this->codigo .= "}\n"; 
        /*********************************************/
y además le agregas también ....


Código:
    /********************************************************/ 
    /*    LeeDatos                                            */ 
    /********************************************************/ 
    function LeeDatos() 
    { 
             
        if ($this->formato == 'GET') 
        { 
            $this->codigo .= "function getInfo(valor,esValue){\n"; 
            if ($this->entrada != '') 
                { 
                $this->codigo .= "valor = document.getElementById('".$this->entrada."').value;"; 
                $this->codigo .= "    http.open('get', '".$this->url."?".$this->entrada."=' + valor);\n"; 
                } 
            else 
                $this->codigo .= "    http.open('get', '".$this->url."' + valor);\n"; 
            $this->codigo .= "    http.onreadystatechange = function(){handleInfo(esValue)};\n"; 
            $this->codigo .= "    http.send(null);\n"; 
            $this->codigo .= "}\n"; 
        } 
        else 
            { 
            $this->codigo .= "function getInfo(valor, esValue){\n"; 
            $this->codigo .= "    http.open('POST', '".$this->url."',true);\n"; 
            $this->codigo .= "    http.onreadystatechange = function(){handleInfo(esValue)};\n"; 
            $this->codigo .= "    http.setRequestHeader(\"Content-Type\", \"application/x-www-form-urlencoded\");\n"; 
            if ($this->entrada != '') 
                { 
                $this->codigo .= "    valor = document.getElementById('".$this->entrada."').value;\n"; 
                $this->codigo .= "    http.send('".$this->entrada."=' + valor);\n"; 
                } 
            else 
                $this->codigo .= "    http.send(null);\n"; 
            $this->codigo .= "}\n"; 
            } 
    } 
    /********************************************************/ 
    /*    EscribeDatos                                        */ 
    /*        - $div     --> Donde volcamos los datos            */ 
    /********************************************************/ 
    function EscribeDatos($div) 
    { 
        /*Funcion q muestra el resultado*/ 
        $this->codigo .= "function handleInfo(esValue){\n"; 
        $this->codigo .= "    if(http.readyState == 1){\n"; 
        $this->codigo .= "        replaceHTML('".$div."', 'Me estoy cargando...',esValue);\n"; 
        $this->codigo .= "    }\n"; 
        $this->codigo .= "    if(http.readyState == 4){\n"; 
        $this->codigo .= "        replaceHTML('".$div."', http.responseText, esValue);\n"; 
        $this->codigo .= "    }\n"; 
        $this->codigo .= "}\n"; 
    }
Ovbiamente fíjate sólo en lo que agregué/cambié en negritas.

Luego cuando quieras usar el asunto le envías el parámetro true o false en la función getInfo() dependiendo de si lo vas a aplicar sobre un campo de formulario o no.

Si es para un campo de form: getInfo(true)
Si es para otro elemento getInfo(false)

No lo he probado pero así a ojo, salvo que se me haya escapado algún error sintáctico y en teoría creo que debería funcionar

Yá me dirás algo.

Un saludo

Última edición por tunait; 12/10/2005 a las 17:34
  #10 (permalink)  
Antiguo 12/10/2005, 18:06
Avatar de SiR.CARAJ0DIDA  
Fecha de Ingreso: junio-2004
Ubicación: Acá
Mensajes: 1.166
Antigüedad: 19 años, 9 meses
Puntos: 4
no entiendo, para que hacer una clase en php que solo imprime codigo javascript? para eso armo funciones o una clase en javascript y lo incluyo en un .js, me parece mas practico
__________________
Internet Explorer SuckS
Download FireFox
  #11 (permalink)  
Antiguo 13/10/2005, 03:27
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
Tunait, muchas gracias, esta noche cuando llegue a casa me pondre con ello.

SiR.CARAJ0DIDA, la verdad es q me estoy planteando hacerlo en JS, pero me parece mas claro para mi usar una clase en PHP. Gracias por la observacion.
__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
  #12 (permalink)  
Antiguo 13/10/2005, 04:45
Avatar de Viet  
Fecha de Ingreso: octubre-2003
Ubicación: Mar del Plata - Argentina
Mensajes: 247
Antigüedad: 20 años, 6 meses
Puntos: 2
Spyn_ET: Me parece muy piola la clase y el ejemplo!... no dejes de compartirlo con nosotros. ;)

Sir.CARACORTADA: porque no lo haces y lo compartes?
__________________
Keep it simple and keep it fast.
  #13 (permalink)  
Antiguo 13/10/2005, 14:37
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
En Javascript encontré esta clase, q quizas os pueda ser util.

Código PHP:
function XMLUtil()
{
    
this.UNINITIALIZED 0;
    
this.LOADING       1;
    
this.LOADED        2;
    
this.INTERACTIVE   3;
    
this.COMPLETE      4;
    
this.isIE = (document.implementation.createDocument) ? false true;
}

XMLUtil.prototype.getXMLHTTPObject = function()
{
    if(
this.isIE)
    {
        return new 
ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        return new 
XMLHttpRequest();
    }
}

XMLUtil.prototype.getDOM = function()
{
    if (
this.isIE)
    {
        return new 
ActiveXObject("Microsoft.XMLDOM");
    }
    else
    {
        return new 
DOMParser();
    }
}

XMLUtil.prototype.getDOMFromString = function(xmlStr)
{
    var 
xmlDom this.getDOM();
    if (
this.isIE)
    {
        
xmlDom.async 'false';
        
xmlDom.loadXML(xmlStr);
        return 
xmlDom;
    }
    else
    {
        return 
xmlDom.parseFromString(xmlStr'text/xml');
    }
}

XMLUtil.prototype.getText = function(elem)
{
    if (
this.isIE)
    {
        return 
elem.text;
    }
    else
    {
        return 
elem.textContent;
    }
}

function 
replaceHTML(idNamecontent)
{
    var 
target document.getElementById(idName);    
    
target.innerHTML content
}
function 
BrowserDetection()
{
    var 
isIEisMozillaisSafariisOpera false;
    if (
navigator.userAgent.indexOf('MSIE') != -1)
        
this.isIE true;
    else if (
navigator.userAgent.indexOf('Safari') != -1)
        
this.isSafari true;
    else if (
navigator.userAgent.indexOf('Opera') != -1)
        
this.isOpera true;
    else
        
this.isMozilla true;

__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
  #14 (permalink)  
Antiguo 14/10/2005, 19:25
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Spyn_ET

Podrías indicar un ejemplo de uso de esa classe en javascript (o de donde la obtuvistes para ver más información sobre su uso?).

Un saludo,
  #15 (permalink)  
Antiguo 15/10/2005, 20:26
 
Fecha de Ingreso: diciembre-2003
Mensajes: 218
Antigüedad: 20 años, 4 meses
Puntos: 0
Código PHP:
var variable "HOLA";
http xmlUtil.getXMLHTTPObject();
http.open('GET''datos.php?id='+variablefalse);
http.send(null);
var 
res "";
if (
http.readyState == xmlUtil.COMPLETE && http.status == 200)
 {
    
res http.responseText;
  }
else if (
http.readyState == xmlUtil.LOADING && http.status == 200)
{
   
res "Cargando...";

No lo he probado, unicamente lo he creado apartir de la clase que he puesto antes, en un principio, lo unico q hace es una conexion (un objeto XMLHttpRequest() ) y luego lanza la ejecucion de la llamada con el parametro HOLA.

Con http.readyState obtenemos el estado actual y si es LOADING, cargamos res con "Cargando..." y si no con el valor devuelto.

Espero q haya qdado algo claro :D
__________________
SymbianForever
SymbianForever.com, todo sobre y para tu symbian
aNieto2K | Themes para WordPress
De todo un poco
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:10.