Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/09/2014, 15:18
_JarC
 
Fecha de Ingreso: septiembre-2010
Mensajes: 12
Antigüedad: 13 años, 7 meses
Puntos: 0
Pregunta Como implementar funcion Ajax-Autocomplete

Buenas parcero

Estoy realziando un proyecto en MCV + ORACLE y estoy en un dilema y no puedo hacer lo mas sencillo creo...

La idea es la siguiente, traigo varios valores de una consulta dinamica id, producto, cantidad, etc.

En la columna productos deseo escribir el id del productos y este me debe mostrar al frente el nombre por medio de una funcion ajax. funciona para la primera columna pero de hay para adelante si escribo en el siguiente ya no funciona pues como todos los input que se generan dinamicamente tienen el mismo name e id pues solo me va a mostrar en el primero.

Pues ya hize alguna pruebas secillas para cambiar el nombre e id del input en +1 pero quiero que cuando llege al ajax este haga lo mismo

Espero haber explicado bn

Aqui les dejo una captura






CONTROLADOR
Código PHP:
public function listarProductosAjax()
     {
         
$aux $_POST['q'];
        
// $aux1 = $_GET['id'];
        

         
$m = new Model(Config::$mvc_bd_usuario,
                     
Config::$mvc_bd_claveConfig::$mvc_bd_hostname);

         
$productoajax $m->verProductoAjax($aux);

         
$paramsVerAjax $productoajax;

        

        return 
$paramsVerAjax;
     } 

MODELO
Código PHP:
     public function verProductoAjax($id)
        {
         
$id htmlspecialchars($id);
         
$id1=1;

         
$sql="select PRO_NOMBRE from PRODUCTOS where PRO_ID LIKE '".$id."%'";


         
$result oci_parse($this->conexion,$sql);
         
oci_execute($resultOCI_DEFAULT);
         
//$devolucion = array();

         
$row oci_fetch_array($result);
        echo 
$row['PRO_NOMBRE'];
        
// $row = $result;
        // return $row;
        


VISTAS
Código PHP:
Ver original
  1. <div class="table-responsive">
  2.  <table align="center" class="table table-condensed table-hover">
  3.      <tr>
  4.          <th>#</th>
  5.          <th>Producto</th>
  6.          <th>...</th>
  7.          <th>Cantidad</th>
  8.          <th>Reserva</th>        
  9.          <th>Producto</th>
  10.          <th>Cantidad</th>
  11.          
  12.          <th>Tipo Reserva</th>
  13.          
  14.  
  15.      </tr>
  16.  
  17. <?php
  18.  
  19.  
  20. ?>
  21.   <?php foreach ($paramsPD['productoD'] as $paramsPD1) :?>
  22. <?php
  23.  
  24.  
  25. $nameb="bus";
  26. $sum++;
  27. //$sumando=$sum+1;
  28. $bus=$nameb.$sum;
  29. echo $bus;
  30. ?>
  31.  
  32.      <tr>
  33.          <td><?php echo $paramsPD1['PD_ID'] ?></td>
  34.          <td>        
  35.  
  36.            
  37. [B]          Buscar <input type="text" id="<?php echo $bus ?>"
  38. name="<?php echo $bus ?>" onkeyup="loadXMLDoc()" required /></td>
  39.  
  40.  <td><div id="myDiv"> </div></td>
  41. [/B]
  42.      
  43.          <td><input type="number" name="cantidad" min="1" required placeholder="Cantidad de Productos" class="form-control" id="" size="" value="<?php echo $paramsPD1['PD_CANTIDAD']?>"/></td>
  44.          
  45.  
  46.  
  47. .....
  48.  
  49.        
  50.      </tr>
  51.      <?php endforeach; ?>



Ajax
Código Javascript:
Ver original
  1. function loadXMLDoc()
  2. {
  3. var xmlhttp;
  4.  
  5. var n=document.getElementById('bus1').value;
  6.  
  7. if(n==''){
  8.  document.getElementById("myDiv").innerHTML="";
  9.  return;
  10. }
  11.  
  12. if (window.XMLHttpRequest)
  13.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  14.   xmlhttp=new XMLHttpRequest();
  15.   }
  16. else
  17.   {// code for IE6, IE5
  18.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  19.   }
  20. xmlhttp.onreadystatechange=function()
  21.   {
  22.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  23.     {
  24.     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  25.     }else{ document.getElementById("myDiv").innerHTML='<img src="load.gif" width="50" height="50" />'; }
  26.   }
  27. xmlhttp.open("POST","index.php?ctl=buscarajax",true);
  28. xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  29. xmlhttp.send("q="+n);
  30. }