Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Votación a sql por php y ajax

Estas en el tema de Votación a sql por php y ajax en el foro de Frameworks JS en Foros del Web. Hola! Tengo un code y un script los cuales muestran un texto aleatorio, el usuario por medio de un form envía una votación a otro ...
  #1 (permalink)  
Antiguo 06/02/2011, 10:12
Avatar de Shaito  
Fecha de Ingreso: agosto-2010
Mensajes: 383
Antigüedad: 13 años, 8 meses
Puntos: 37
Exclamación Votación a sql por php y ajax

Hola!

Tengo un code y un script los cuales muestran un texto aleatorio, el usuario por medio de un form envía una votación a otro php y se registra en la DB y muestra nuevamente otro texto aleatorio. Hasta ahí bien, el problema surge cuando nuevamente se vota, ya que el script de ajax no actúa nuevamente y redirige al php donde se envía la votación y se muestra el nuevo texto.

A diferencia de la vez anterior, esta lo hace desde el archivo.php directo, mientras la que la 1º vez lo hace desde un index con include al form que muestra el texto.

Les dejo mis codes para ver si me pueden ayudar:

Script ajax:
Código Javascript:
Ver original
  1. <script language="javascript">
  2. $(document).ready(function() {
  3.     $().ajaxStart(function() {
  4.         $('#loading').show();
  5.         $('#result').hide();
  6.     }).ajaxStop(function() {
  7.         $('#loading').hide('slow');
  8.         $('#result').fadeIn('slow');
  9.        
  10.     });
  11.     $('#form, #fat, #fo3').submit(function() {
  12.         $.ajax({
  13.             type: 'POST',
  14.             url: $(this).attr('action'),
  15.             data: $(this).serialize(),
  16.             success: function(data) {
  17.                 $('#result').html(data);
  18.  
  19.             }
  20.         })
  21.         return false;
  22.     });
  23. })  
  24. </script>

Y php's

Moderar (muestra el texto y el form de votación)
Código PHP:
Ver original
  1. $result = mysql_query("SELECT * FROM historia where estado=0 and baneado=0 order by RAND() LIMIT 1");
  2. $mostrar = mysql_fetch_array($result);
  3. if($row = $mostrar)
  4. {
  5. echo'<div class="entrada" accept-charset="UTF-8">
  6. <h3>' . $row['titulo'] . '</h3>
  7. '.$row['resumen'].' ...
  8. <p style="float:right"><a href="index.php?p=leer&h=' . $row['id'] . '">Seguir leyendo</a></p>
  9. <br><br>
  10.  
  11. <table style="height:5px"><tr style="height:5px">
  12. <td style="height:5px">
  13. <form id="fo3" name="fo3" action="votado.php" method="post">
  14. <input type="hidden" name="id" value="'.$row["id"].'">
  15. <input type="hidden" name="v" value="votop">
  16. <input type="submit" value="   " style="border:none; background-image:url(posi.png); background-repeat:no-repeat;">
  17. </form>
  18.  
  19. </td><td style="height:5px">
  20. <form id="fo3" name="fo3" action="votado.php" method="post" >
  21. <input type="hidden" name="id" value="'.$row["id"].'">
  22. <input type="hidden" name="v" value="votom">
  23. <input type="submit" value="    " style="border:none; background-image:url(nega.png); background-repeat:no-repeat;">
  24. </tr>
  25. </table>
  26. </form>
  27. </div>
  28. </div>
  29. ';
  30. }
Votado.php (envió de puntos)
Código PHP:
Ver original
  1. <?
  2. include("config.php");
  3. $id=$_POST['id'];
  4. if($_POST['v']=='votop')
  5. {
  6. $sSQL=("UPDATE historia SET positivos=positivos+1 Where id='$id'") or die("Fallo al votar");
  7. mysql_query($sSQL);
  8.  
  9. $votado=mysql_query("select * from historia where id='$id'")or die("La base de datos no existe");
  10. while ($row=mysql_fetch_array($votado))
  11. {
  12. include('moderar.php');
  13. }
  14. }
  15. elseif($_POST['v']=='votom')
  16. {
  17. $sSQL=("UPDATE historia SET negativos=negativos-1 Where id='$id'") or die("Fallo al votar");
  18. mysql_query($sSQL);
  19.  
  20. $votado=mysql_query("select * from historia where id='$id'")or die("La base de datos no existe");
  21. while ($row=mysql_fetch_array($votado))
  22. {
  23. include('moderar.php');
  24. }
  25. }
  26. ?>

Espero que me puedan ayudar.

Un saludo y gracias!
__________________
Shaito Hiraga - Diseñador CSS

Etiquetas: ajax, fallo, php, votacion
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




La zona horaria es GMT -6. Ahora son las 07:25.