Regresar   Foros del Web > Programación para sitios web > AJAX

El registro es Gratis en Foros del Web
Respuesta
 
Herramientas Buscar en Tema Desplegado
Antiguo 26/03/08, 13:34:37   #1 (permalink)
barto3x ha deshabilitado el Karma
 
Registrado: ene 2008
Mensajes: 27
barto3x is offline  
cargar datos php + ajax prototype

Hola a todos. mi situacion es la siguiente: estoy iniciandome en el mundo ajax (usando la libreria prototype) y estoy realizando un mantenedor de usuarios para poder ingresar y buscar los usuarios. el ingreso ya lo tengo realizado y para buscar me gustaria que al digitar en el mismo campo que estoy ingresando busque y me carge los datos en los input que estan destinados para ingresar: el formulario es el siguiente:

Código PHP:

function Formulario()
    {    
        // *********************************
        // OBTENCION DE LOS NOMBRES DE PERFIL
        $this->db->PConnect();
        //$this->db->debug=1;

        $array = array();
        $sql = "SELECT * FROM perfiles ORDER BY perfil_nombre";
        $res = $this->db->GetArray($sql);
        if ( $res ) {
            //$array = $res;
            $perfiles = $res;
        }
        $this->db->Close();
        
        ?>
        
        <html>
        <head>
        <link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />
        <script src="../js/usuarios.js" type="text/javascript"></script>
        <script src="../js/prototype.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/livevalidation_standalone.compressed.js"></script>
        </head>
        
        <body style="background:#FFF">
        <div class="box" style="width:740px !important; margin:0; border:0">
        
        <form id="data_form">

        <div class="box-form">
        <center>          
              <label class="form-header" style="width:99%"><?php echo "Registro Usuarios" ?></label>
              </center>
                
              <div class="form-title">* Nombre:</div>
              <div class="form-data"><?php echo $this->html->inputText("usuario_nombre"""6060"""id=\"nombre\""?></div>
              
              <div class="form-title">* Usuario:</div>
              <div class="form-data"><?php echo $this->html->inputText("usuario_login"""60100"""id=\"login\""?>
        <?php echo $this->html->botones("comprobar""button""onclick=\"ComprobarUsuario()\"");?>
        <img id="loading" src="../images/ajax-loader.gif" style="display:none">
        </div>
          
              <div class="form-title">* Password:</div>
              <div class="form-data"><?php echo $this->html->inputText("usuario_password"""1515"""id=\"password\""?></div>
              
              <script type="text/javascript">
          var nombre = new LiveValidation('nombre');
            var login = new LiveValidation('login');
            var password = new LiveValidation('password');
            
            nombre.add(Validate.Presence( 'hello world', { failureMessage: "Debe ingresar!" } ));
            login.add(Validate.Presence( 'hello world', { failureMessage: "Debe ingresar!" } ));
            password.add(Validate.Presence( 'hello world', { failureMessage: "Debe ingresar!" } ));
        </script>  
              
              <div class="form-title">* Perfil:</div>
          <div class="form-data">
              <select name="perfiles" size="1">
              <option value="none" selected> Seleccione... </option>
                <?php
                    
foreach ($perfiles as $key => $row) {
                        
?>
                        <option value="<?php echo $row["id_perfil"]; ?>"><?php echo $row["perfil_nombre"]; ?></option>
                        <?php
                    
// FIN FOREACH
                
?>
                </div>
        </div>

              <div class="botones">
              <?php
                  
echo $this->html->botones("guardar""button""onclick=\"GuardarUsuario()\"");
                  echo 
$this->html->botones("cancelar""button""onclick=\"CancelarVideo()\"");
                  echo 
$this->html->botones("listar""button""onclick=\"MostrarUsuarios()\"");
              
?>
              </div>
                          
          </div>

        </form>
        </div>
        
        <div id="comprobacion">    
    </div>
            
        </body>
        <html>

        <?php
    
}
y para buscar lo hago de la siguiente forma:

Código PHP:
function comprobar(){
    
    $data = $_POST;
        if ( $data['boton']=="comprobar" ) {
        
          parse_str($_POST['data'], $data);
          $login = $data['usuario_login'];
                 
          // BUSCANDO EL LOGIN
          $this->db->PConnect();
          $usuarios = array();
        $sql_buscar = "SELECT * FROM usuarios WHERE usu_login = '$login'"; 
          $res_buscar = $this->db->GetRow($sql_buscar);
          if( $res_buscar ){
          $usuarios = $res_buscar;
      }
      $this->db->Close();
        
      // SI EL USUARIO EXISTE EN LA BASE
      if( $usuarios['usu_login'] == $login ){
        $comentario = "el usuario ya existe";
        
        $this->db->PConnect();
            $usuarios = array();
          $sql_buscar = "SELECT * FROM usuarios WHERE usu_login = '$login'"; 
            $res_buscar = $this->db->GetRow($sql_buscar);
            if( $res_buscar ){
            $usuarios = $res_buscar;
        }
        $this->db->Close();
        
        $datos = array();
        $datos[0] = $usuarios['usu_login']; 
        $datos[1] = $usuarios['usu_nombre'];
        $datos[2] = $usuarios['usu_pass'];
        ?>
        
        <div id="ulogin"> <?php echo $datos[1]; ?> </div>
        <div id="unombre"> <?php echo $datos[0]; ?> </div>
        <div id="upass"> <?php echo $datos[2]; ?> </div>       
        
        <?php 
      
}
      
// SI EL USUARIO NO EXISTE
      
else{
        
$comentario "El usuario no se encuentra registrado";  
      }
        } 
// fin boton comprobar    
        
echo $comentario;
        
//echo $datos;
        
return $datos;
  }
esta es mi funcion ajax para buscar al usuario:

Código:
function ComprobarUsuario(){
  //if( ValidarUsuario() ){
    $("loading").style.display = "";  
    var post = Form.serialize($("data_form"));
    var ajax = new Ajax.Request("usuarios.php", {      
        parameters: { action:"comprobar", boton:"comprobar", data:post },
        onSuccess: function(transport){
    		$("comprobacion").innerHTML = transport.responseText;
    		$("comprobacion").style.display = "";
    		$("loading").style.display = "none";
    	  }
     });
  //}
}
lo que deseo es que si encuentra al usuario digitado en el campo login, me carge los datos en los input del formulario. en la funcion comprobar, busco los datos y me los encuentra,. mi consulta es como puedo cargar esos datos en el formulario que esta en la funcion formulario.

espero que puedan ayudarme, agradecido de antemano
  Responder Con Cita
Respuesta


Califica este Tema - cargar datos php + ajax prototype.

Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado Califica este Tema
Califica este Tema:

Reglas del foro
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está activado
Las caritas están activado
Código [IMG] está activado
Código HTML está desactivado


Todas las horas son GMT -6. La hora es 13:14:14.

Message Board Statistics

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95