Foros del Web » Programando para Internet » Javascript »

refrscar un formulario con ajax

Estas en el tema de refrscar un formulario con ajax en el foro de Javascript en Foros del Web. entonces por lo que veo el error debe estar aca puedes decirme que te devuelve el $conexion->consultar($consulta); te devuelve esto un mysql_query...

  #31 (permalink)  
Antiguo 26/09/2012, 11:55
Avatar de Dradi7  
Fecha de Ingreso: junio-2008
Ubicación: Peru - Lima
Mensajes: 1.518
Antigüedad: 15 años, 10 meses
Puntos: 220
Respuesta: refrscar un formulario con ajax

entonces por lo que veo el error debe estar aca puedes decirme que te devuelve el
$conexion->consultar($consulta); te devuelve esto un mysql_query
__________________
La clave de todo triunfador es eliminar todas sus excusas y sus limitaciones
  #32 (permalink)  
Antiguo 26/09/2012, 12:03
 
Fecha de Ingreso: septiembre-2012
Ubicación: Sevilla
Mensajes: 144
Antigüedad: 11 años, 6 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. ?>
  #33 (permalink)  
Antiguo 27/09/2012, 11:59
 
Fecha de Ingreso: septiembre-2012
Ubicación: Sevilla
Mensajes: 144
Antigüedad: 11 años, 6 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. ?>
  #34 (permalink)  
Antiguo 27/09/2012, 11:59
 
Fecha de Ingreso: septiembre-2012
Ubicación: Sevilla
Mensajes: 144
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: refrscar un formulario con ajax

muchisimas gracias pr tu tiempo y pr tu atencin eres genial Dradi7
  #35 (permalink)  
Antiguo 25/06/2014, 07:17
 
Fecha de Ingreso: mayo-2012
Ubicación: asuncion
Mensajes: 1
Antigüedad: 11 años, 11 meses
Puntos: 0
Respuesta: refrscar un formulario con ajax

hola quisiera saber si hay alguna actualizacion de este tema. gracias

Etiquetas: ajax, formulario, input, php, select
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 03:28.