Ver Mensaje Individual
  #32 (permalink)  
Antiguo 26/09/2012, 12:03
nataliagb1992
 
Fecha de Ingreso: septiembre-2012
Ubicación: Sevilla
Mensajes: 144
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: refrscar un formulario con ajax

pagina 1
Código HTML:
Ver original
  1. [HIGHLIGHT="PHP"]<?php
  2. header("Content-Type: text/html;charset=utf-8");
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  6.     <head>
  7.         <title>Entrada de Almacen</title>
  8.         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  9.         <meta http-equiv="Content-Style-Type" content="text/css" />
  10.         <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  11.         <link rel="stylesheet" type="text/css" media="screen" href="cssPageGrid.css" />
  12.         <link rel="stylesheet" type="text/css" media="screen" href="tema/css/custom-theme/jquery-ui-1.8.23.custom.css" />
  13.         <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
  14.         <link rel="stylesheet" type="text/css" media="screen" href="css/ui.multiselect.css" />
  15.  
  16.         <script src="js/jquery.min.js" type="text/javascript"></script>
  17.         <script src="js/jquery-ui-custom.min.js" type="text/javascript"></script>
  18.         <script src="js/jquery.layout.js" type="text/javascript"></script>
  19.         <script src="js/i18n/grid.locale-es.js" type="text/javascript"></script>
  20.         <script type="text/javascript">
  21.             $.jgrid.no_legacy_api = true;
  22.             $.jgrid.useJSON = true;
  23.         </script>
  24.         <script src="js/ui.multiselect.js" type="text/javascript"></script>
  25.         <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
  26.         <script src="js/jquery.tablednd.js" type="text/javascript"></script>
  27.         <script src="js/jquery.contextmenu.js" type="text/javascript"></script>
  28.     </head>
  29.     <body>
  30.         <div id="formularioArt">
  31.             <form action="entradaArticulo.php" method="post">
  32.                 <legend>Entrada Almacén</legend>
  33.                 <br/>
  34.                 <label>Código de Barras</label>
  35.                 <input name="cBar" id="cBar" type="text" size="20" maxlenght="200" autofocus/>
  36.                 <br/>
  37.                 <label>Fecha Entrada:</label>
  38.                 <script>
  39.                     $(function() {
  40.                         $( "#fechaFactura" ).datepicker({
  41.                             showOtherMonths: true,
  42.                             selectOtherMonths: true,
  43.                             dateFormat:'dd/mm/yy',
  44.                             firstday:1
  45.                         });  
  46.                         $('#fecha').datepicker($.datepicker.regional['es']);                                  
  47.                     });
  48.                 </script>
  49.                 <input type="text" id="fechaFactura" name="fechaFactura" maxlenght="5" />
  50.                 <br/>
  51.  
  52.                 <label>Nº de Serie:</label>
  53.                 <input name="numSer" id="numSer" type="text" size="30" maxlenght="200"/><br/>
  54.                 <script>
  55.                    $(document).ready(function(){
  56.                         $('#cBar').keydown(function(event){
  57.                             if (event.which == 13) {
  58.                                 $.ajax({
  59.                                     url: 'ajax.php',
  60.                                     type: 'POST',
  61.                                         data: 'cBar=' + $(this).val(),
  62.                                     success: function(data){
  63.                                         $('resultado').val(data);
  64.                                     }
  65.                                 });
  66.                                 event.preventDefault();
  67.                             }
  68.                         });
  69.                     });
  70.     /* function ajax(cBar){
  71.      $.post("ajax.php",{cBarras:cBar},function(respuesta){
  72.         jQuery("#resultado").html(respuesta);
  73.     });
  74.     }*/
  75.    
  76.                 </script>
  77.                 <div id="resultado"></div>
  78.              
  79.                 <input id="enviar" name="enviar" type="submit" value="Aceptar" />
  80.             </form>
  81.         </div>
  82.  
  83.     </body>
  84. </html>
[/HIGHLIGHT]

pagina2:

Código PHP:
Ver original
  1. <?php
  2. header("Content-Type: text/html;charset=utf-8");
  3. /* al rellenar el codigo de barras se nos muestra la informacion del producto
  4.  * http://www.forosdelweb.com/f13/ajax-php-conectada-con-resultados-base-datos-1015007/
  5.  */
  6. include_once 'clases/Class_Bd.php';
  7. echo  " <link rel='stylesheet' type='text/css' media='screen' href='cssPageGrid.css' />";
  8.  
  9. $conexion = new Conecta_DB;
  10. $conexion->conectar();
  11. $res = $_POST['cBar'];
  12. echo "la variable es :".$res;
  13. $consulta = "SELECT nombre,descripcion,familia FROM altaArticulos WHERE cBarras='$res'";
  14. echo '<br>';
  15. $query = $conexion->consultar($consulta);
  16. /*echo "<tabla id='tabla'>
  17.         <tr>
  18. <td id='td1'>Nombre del Producto|</td><td id='td1'>Descripción del Producto|</td><td id='td1'>Familia del Producto</td>
  19. </tr> <tr>" ;
  20.  
  21. foreach($query as $row){
  22.     echo "<td>";
  23.     echo $row[0]['nombre'];
  24.     echo "</td><td>";
  25.     echo $row[1]['descripcion'];
  26.     echo "</td><td>";
  27.     echo $row[2]['familia'];
  28. }
  29. echo"</tr></table>";*/
  30.     while ($row = mysql_fetch_assoc($query)) {
  31.         $aviso0 = $row['nombre'];
  32.         $aviso1 = $row['descripcion'];
  33.         $aviso2 = $row['familia'];
  34.         $aviso = "Articulo " . $aviso0 . "con la descripción " . $aviso1 . "que pertenece a la familia " . $aviso2 . ".";
  35.         print "<textarea id='resultado'>" . $aviso . "</textarea>";
  36.     }
  37.    
  38.  /*   while ($row = mysql_fetch_array($query,MYSQL_NUM)) {
  39.         $aviso0 = $row[0];
  40.         $aviso1 = $row[1];
  41.         $aviso2 = $row[2];
  42.         $aviso = "Articulo " . $aviso0 . "con la descripción " . $aviso1 . "que pertenece a la familia " . $aviso2 . ".";
  43.         print "<textarea id='resultado'>" . $aviso . "</textarea>";
  44.     }
  45. while ($row = mysql_fetch_array($query)) {
  46.     $aviso0 = $row[0]['nombre'];
  47.     $aviso1 = $row[1]['descripcion'];
  48.     $aviso2 = $row[2]['familia'];
  49.     $aviso = "Articulo " . $aviso0 . "con la descripción " . $aviso1 . "que pertenece a la familia " . $aviso2 . ".";
  50.     print "<textarea id='resultado'>" . $aviso . "</textarea>";
  51. }*/
  52. ?>