Problema con consulta usando jquery

Buenas estoy tratando de hacer una consulta a mi bd con jquery pero no me funciona aqui paso los codigos

HTML

<script type="text/javascript" src="JS/funciones.js"> </script>
<script type="text/javascript" src="JS/jquery.js"> </script>
<title>Documento sin título</title>
</head>

<body>
<table width="354" border="1">
<tr>
<td>Banco</td>
<td>Numero de Deposito</td>
<td>Monto</td>
<td>Usuario</td>
</tr>
<tr>
<td><input name="Banco" type="text" id="banco" value="" /></td>
<td><input name="n_deposito" type="text" id="n_deposito" value="" /></td>
<td><input name="monto" type="text" id="monto" value="" /></td>
<td><input name="usuario" type="text" id="usuario" value=""/></td>
<td> <input type="button" name="button" id="button" style="height:50px; width:100px; font-size:20px;" value="Consultar" onclick="consultar()"></td>
</tr>
</table>

funcion en ajax-jquery para consultar

function consultar()
{
banco = $("#banco").val('$banco')
n_deposito = $("#n_deposito").val()
monto = $("#monto").val()
usuario = $("#usuario").val()
$.post('php/consulta.php')

}

php que hace la consulta

<?php

mysql_connect ("localhost", "root", "root");
mysql_select_db ("sistema");
$sql="SELECT * from deposito";
$cap=mysql_query($sql) or die ("ERROR EN CONSULTA");
?>
<?php while($f=mysql_fetch_array ($cap)){?>
<td><?=$f["banco"];?></td>
<td><?=$f["n_deposito"];?></td>
<td><?=$f["monto"];?></td>
<td><?=$f["usuario"];?></td>
</tr>

<?php }


?>

1 respuesta

Respuesta
1

Te falta serializar los datos del formulario banco, n_deposito: anexo ejemplo:

http://stackoverflow.com/questions/3328365/jquery-post-a-serialized-form-then-inserting-into-mysql-via-php 

  $('form').submit(function(msg) {  
        alert($(this).serialize()); // check to show that all form data is being submitted
        $.post("post.php",$(this).serialize(),function(data){
            alert(data); //post check to show that the mysql string is the same as submit                        
        });
        return false; // return false to stop the page submitting. You could have the form action set to the same PHP page so if people dont have JS on they can still use the form
    });

La parte que dice: $(this).serialize   <-- este método reúne todos los parámetros que tienes y los envía al archivo php que los recibe, los datos regresan en data en la linea que dice: alert(data).

Aunque a mi criterio tienes otra forma más rápida de insertar y ver datos, te dejo unos vídeos de un curso que se esta impartiendo y en especial este vídeo:

https://www.youtube.com/watch?v=OC7PIp8gndA 

Lo importante es que recuerdes que hay herramientas que nos ayudan a crear webs mucho más rápido y de manera automatizada y que se pueden aprovechar para generarlas, te dejo el enlace del curso completo: https://www.youtube.com/watch?v=O7235gDghMU&list=PLSuKjujFoGJ1Xyq6FYGkPOQ3yzrCE-gW1 

Gracias por suscribirte al canal:https://www.youtube.com/user/dimit28 

y gracias por visitar: http://develoteca.com

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas