Ver Mensaje Individual
  #33 (permalink)  
Antiguo 27/09/2012, 11:59
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

pr fin el problema se slucin ha quedado así:
pagina 1

Código HTML:
Ver original
  1. <?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 required/>
  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" required/>
  50.                 <br/>
  51.  
  52.                 <label>Nº de Serie:</label>
  53.                 <input name="numSer" id="numSer" type="text" size="30" maxlenght="20" required/><br/>
  54.                 <script>
  55.                  
  56.                    
  57.                   $(document).ready(function(){
  58.                         $('#cBar').keydown(function(event){
  59.                             if (event.which == 13) {
  60.                                 $.ajax({
  61.                                     url: 'ajax.php',
  62.                                     type: 'POST',
  63.                                         data: 'cBar=' + $(this).val(),
  64.                                     success: function(data){
  65.                                         $('#resultado').html(data);
  66.                                     }
  67.                                 });
  68.                                 event.preventDefault();
  69.                             }
  70.                         });
  71.                     })
  72.    
  73.    
  74.                 </script>
  75.                <!-- <table id="latabla"></table>
  76.                <input type="button" id="mostrar" value="Mstra"/>-->
  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>

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. //$res2=123;
  13. //echo "la variable es :".$res;
  14. $consulta = "SELECT cBarras,nombre,descripcion,familiaArt FROM altaArticulos WHERE cBarras='$res' limit 1";
  15.  
  16. $query = $conexion->consultar($consulta);
  17. //print_r($query);
  18. /*
  19.     while ($row = mysql_fetch_assoc($query)) {
  20.         $aviso0 = $row['nombre'];
  21.         $aviso1 = $row['descripcion'];
  22.         $aviso2 = $row['familia'];
  23.         $aviso = "Articulo " . $aviso0 . "con la descripción " . $aviso1 . "que pertenece a la familia " . $aviso2 . ".";
  24.         print "<textarea id='resultado'>" . $aviso . "</textarea>";
  25.     }*/
  26.    
  27. foreach($query as $row){
  28. $aviso0 = $row['nombre'];
  29. $aviso1 = $row['descripcion'];
  30. $aviso2 = $row['familiaArt'];
  31. $aviso = "Articulo: " . $aviso0 . ", con la descripción: " . $aviso1 . ", que pertenece a la familia:  " . $aviso2 . ".";
  32. echo "<textarea id='resultado'>" . $aviso . "</textarea>";
  33. }
  34.  /*   while ($row = mysql_fetch_array($query,MYSQL_NUM)) {
  35.         $aviso0 = $row[0];
  36.         $aviso1 = $row[1];
  37.         $aviso2 = $row[2];
  38.         $aviso = "Articulo " . $aviso0 . "con la descripción " . $aviso1 . "que pertenece a la familia " . $aviso2 . ".";
  39.         print "<textarea id='resultado'>" . $aviso . "</textarea>";
  40.     }
  41.  
  42. }*/
  43. ?>