Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/06/2013, 08:20
edie8
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 5 meses
Puntos: 10
Respuesta: insertar datos sin refrescar

No era exactamente lo que quería pero más o menos me vale con css lo mejorare y me funciona lo que conseguí, me gustaría saber si se puede cambiar al hacer click y que este registre en la base de datos los datos que el botón se inhabilite y cambie el enviar por ejemplo por un pendiente de confirmación se puede hacer tal cosa?? mi codigo actual es este:
Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2.   <head>
  3.     <title>Enviar un formulario con jQuery sin recargar la pagina</title>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  6.     <script type="text/javascript" src="funcion.js"></script>
  7.    
  8.   </head>
  9.   <body>
  10.     <form name="form1" id="form1" method="post">
  11.         <input type="hidden" name="id" id="name" value="14">
  12.         <input type="hidden" name="id_lo" id="lastname" value="45">
  13.           <button type="submit" name="enviar" >Enviar</button>
  14.     </form>
  15.   </body>
  16. </html>
send.php
Código PHP:
Ver original
  1. <?php
  2. include('config.php');
  3. echo  $id=$_POST['id'];
  4. $id_o=$_POST['id_lo'];
  5. $sql = mysql_query("INSERT INTO `amigos` (id,id_lo,id_yo)  VALUES ('null',$id,$id_o)",$conexion);
  6. ?>
funcion.js
Código Javascript:
Ver original
  1. $(function(){
  2.         $("#form1").submit(function(){
  3.           $.ajax({
  4.             type:"POST",
  5.             url:"send.php",
  6.             dataType:"html",
  7.             data:$(this).serialize(),
  8.         })
  9.           return false;
  10.         })
  11.  
  12.       })
Espero me puedan ayudar, perdón por mi ortografía acostumbrado a los chat y móvil al escribir rápido se me va lo siento. un saludo.