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

No me canciona este script (Primiparo)

Estas en el tema de No me canciona este script (Primiparo) en el foro de Frameworks JS en Foros del Web. Jovenes aun, como les ha ido? Es que estoy acomodando un script encontrado en http://www.dhtmlgoodies.com/index.ht..._client_lookup y no me ha querido cancionar. La idea es que ...
  #1 (permalink)  
Antiguo 06/05/2006, 10:07
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
No me canciona este script (Primiparo)

Jovenes aun, como les ha ido?

Es que estoy acomodando un script encontrado en
http://www.dhtmlgoodies.com/index.ht..._client_lookup
y no me ha querido cancionar. La idea es que al capturar el Id de un cliente me traiga algunos datos de la Base de Datos (Que pena la falta de redundancia). El caso es que no esta llegando a el script PHP que se encarga de hacer la consulta. El codigo HTML es el siguiente (Simplificado):

Código PHP:
/************************************************************************************************************
    (C) www.dhtmlgoodies.com, November 2005
    
    This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.    
    
    Terms of use:
    You are free to use this script as long as the copyright message is kept intact. However, you may not
    redistribute, sell or repost it without our permission.
    
    Thank you!
    
    www.dhtmlgoodies.com
    Alf Magne Kalleland
    
    ************************************************************************************************************/    
    
var ajax = new sack();
    var 
currentClientID=false;

    function 
getClientData()
    {
        var 
clientId document.getElementById("nit").value.replace(/[^0-9]/g,'');
        if(
clientId.length && clientId!=currentClientID) {
            
currentClientID clientId;
[
b]            ajax.requestFile 'getClient.php?getClientId='+clientId;    [/b]// Specifying which file to get
            
ajax.onCompletion showClientData();    // Specify function that will be executed after file has been found
            
ajax.runAJAX();        // Execute AJAX function            
        
}
        
    }
    
    function 
showClientData()
    {
        var 
formObj document.forms['clientForm'];
        eval(
ajax.response);
    }
    
    function 
initFormEvents()
    {
        
document.getElementById('nit').onblur getClientData();
        
document.getElementById('nit').focus();
    }
    
    
    
window.onload initFormEvents;

    
</script>
</head>

<body>
    <form name="clientForm" action="clientes.htm" method="post">
        <legend>Informacion de Clientes</legend>
        <table>
            <tr>
                <td>Nit :</td>
                <td><input name="nit" id="nit" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Nombre :</td>
                <td><input name="nombre" id="nombre" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Direccion :</td>
                <td><input name="direccion" id="direccion" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Telefono :</td>
                <td><input name="telefono" id="telefono" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Ciudad :</td>
                <td><input name="ciudad" id="ciudad" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Clase :</td>
                <td><input name="clase" id="clase" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Estado :</td>
                <td><input name="estado" id="estado" size="15" maxlength="14"></td>
            </tr>
        </table>    
    </form>
</body>
</html> 
Y el codigo PHP (getClient.php) es el siguiente

Código PHP:
<?php

  session_start
();
/* Replace the data in these two lines with data for your db connection */
  
include ('lee_base.php');
  include (
'configuracion/abrirbd.php');

echo 
"AQUI LLEGUE<hr>"print_r($_GET); flush(); ob_flush(); die;

if(isset(
$_GET['getClientId'])) {  
  
$nit $_GET['getClientId'];
  
$inf lee_todo("Select nombre, direccion, telefono, ciudad, clase, estado from nits where nit=$nit");
  if(
count($inf) > 0) {
    echo 
"formObj.nombre.value = '".$inf["nombre"]."';\n";    
    echo 
"formObj.direccion.value = '".$inf["direccion"]."';\n";    
    echo 
"formObj.telefono.value = '".$inf["telefono"]."';\n";    
    echo 
"formObj.ciudad.value = '".$inf["ciudad"]."';\n";    
    echo 
"formObj.clase.value = '".$inf["clase"]."';\n";    
    echo 
"formObj.estado.value = '".$inf["estado"]."';\n";    
    
  } else {
    echo 
"formObj.nombre.value = '';\n";    
    echo 
"formObj.direccion.value = '';\n";    
    echo 
"formObj.telefono.value = '';\n";    
    echo 
"formObj.ciudad.value = '';\n";    
    echo 
"formObj.clase.value = '';\n";    
    echo 
"formObj.estado.value = '';\n";      
  }    
}
?>
Como les digo, no me ejecuta el codigo PHP. Por que?

Agradezco de antemano su Colaboracion

Un Cordial Saludo
  #2 (permalink)  
Antiguo 06/05/2006, 17:11
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
HOLA AUGUSTO_JARAMIL,

Una vez analizado y haciendo pruebas.... como que le pegue al perro.

Te envio los scripts corregidos... (A mi me canciono como vos decis pero falto un detalle pendiente que al final te lo comento)

El codigo HTML quedaria asi;

Código PHP:
    var ajax = new sack();
    var 
currentClientID=false;

    function 
getClientData()
    {
        var 
clientId document.getElementById("nit").value.replace(/[^0-9]/g,'');
        if(
clientId.length && clientId!=currentClientID) {
            
currentClientID clientId;
            
ajax.requestFile 'consulta.php?getClientId='+clientId;
            
//ajax.onCompletion = showClientData();
                        //ajax.onCompletion = function () {alert(ajax.response);}
                        
ajax.onCompletion = function () {showClientData()}
            
ajax.runAJAX();
        }
        
    }
    
    function 
showClientData()
    {
        var 
formObj document.forms['clientForm'];
        eval(
ajax.response);
    }
    
    function 
initFormEvents()
    {
        
document.getElementById('nit').onblur getClientData();
        
document.getElementById('nit').focus();
    }
    
    
    
window.onload initFormEvents;

    
</script>
</head>

<body>
    <form name="clientForm" action="consulta.php" method="post">
        <legend>Informacion de Clientes</legend>
        <table>
            <tr>
                <td>Nit :</td>
                <td><input name="nit" id="nit" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Nombre :</td>
                <td><input name="nombre" id="nombre" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Direccion :</td>
                <td><input name="direccion" id="direccion" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Telefono :</td>
                <td><input name="telefono" id="telefono" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Ciudad :</td>
                <td><input name="ciudad" id="ciudad" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Clase :</td>
                <td><input name="clase" id="clase" size="15" maxlength="14"></td>
            </tr>
            <tr>
                <td>Estado :</td>
                <td><input name="estado" id="estado" size="15" maxlength="14"></td>
            </tr>
        </table>    
    </form>
</body>
</html> 
Si notas la linea 10 la tengo en comentario (linea como viene el script original) porque me reporta un error onCompletion is not a function cosa rara que tiene el script ajax.js y que no supe que era.... Si alguien lo sabe le agradeceria me lo comentara (gracias)

La linea 11 tambien la tengo comentada. Si la dejo me muestra en una ventana la respuesta que da el servidor (a manera de alert)

Al fin la linea 12 es la que me da la respuesta para enviarla al form

Aqui si hay una cosa rara , la que te comentaba al inicio de la respuesta, en la linea 26, no se por que diantres no me detecta el onblur ..... tuve que oprimir la tecla F5 para que me detectara el cambio....

El script PHP quedaria asi:

Código PHP:
<?php
  ini_set
('session.cache_limiter''');
  
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
  
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  
header('Pragma: no-cache');
  
session_start(); 
/* Replace the data in these two lines with data for your db connection */
  
include ('lee_base.php');
  include (
'configuracion/abrirbd.php');

if(isset(
$_GET['getClientId'])){  
  
$nit $_GET['getClientId'];
  
$sql "Select nombre, direccion, telefono, ciudad, clase, estado from nits where nit=$nit";
  
$inf lee_todo($sql);

  if(
count($inf) > 0) {
    echo 
"formObj.nombre.value = '".$inf[0]["nombre"]."';\n";    
    echo 
"formObj.direccion.value = '".$inf[0]["direccion"]."';\n";    
    echo 
"formObj.telefono.value = '".$inf[0]["telefono"]."';\n";    
    echo 
"formObj.ciudad.value = '".$inf[0]["ciudad"]."';\n";    
    echo 
"formObj.clase.value = '".$inf[0]["clase"]."';\n";    
    echo 
"formObj.estado.value = '".$inf[0]["estado"]."'\n";    
    
  }else{
    echo 
"formObj.nombre.value = '';\n";    
    echo 
"formObj.direccion.value = '';\n";    
    echo 
"formObj.telefono.value = '';\n";    
    echo 
"formObj.ciudad.value = '';\n";    
    echo 
"formObj.clase.value = '';\n";    
    echo 
"formObj.estado.value = ''\n";      
  }    
}
?>
SI miras la lineas 22 y 30 le quite los ";" que hay antes del "\n" ya que, si los dejo, cuando el script html recibe el resultado se queda como esperando algun dato adicional

Espero te sirva

Un Cordial Saludo
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 09:36.