Ver Mensaje Individual
  #28 (permalink)  
Antiguo 13/06/2014, 12:28
Avatar de warywin
warywin
 
Fecha de Ingreso: octubre-2013
Mensajes: 155
Antigüedad: 10 años, 6 meses
Puntos: 1
Respuesta: Cambiar div sin recargar pag

video.php:
Código HTML:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  3. <title>mee</title>
  4. <link href="estyle.css" media="screen" rel="stylesheet" type="text/css" />
  5. <script type='text/javascript' src="jquery1.3.pack.js"></script>
  6. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  7.  
  8. </head>
  9.        <Por aqui parte de pagina></pag>
  10.    
  11.     <div class="votacion">
  12.             <div class="votobtn">
  13.              
  14.                 <button data-estado="like" data-ide="<?php echo $id ?>" id="ejemplo1" >Like</button>
  15.                 <button data-estado="dislike" data-ide="<?php echo $id ?>" id="ejemplo2"/>Dislike</button>
  16.                
  17.                 </div>          
  18.         </div>
  19.  
  20.         <!--form votar sin recargar-->
  21. <script type = "text/javascript">
  22.     var boton1 = document.getElementById("ejemplo1"),
  23.     var boton2 = document.getElementById("ejemplo2"),
  24.    
  25. boton1.addEventListener("click", function(){
  26.     var estado = this.getAttribute("data-estado");
  27.     var idVi = this.getAttribute("data-ide");
  28.    
  29.     $.ajax({
  30.         url: "votosbtn.php",
  31.         type: "POST",
  32.         data: {
  33.             id: idVi,
  34.             valor: estado
  35.         }
  36.         success: function(data) {
  37.                 $('.votobtn').html(data);
  38.             }
  39.     });
  40. }, false);
  41. boton2.addEventListener("click", function(){
  42.     var estado = this.getAttribute("data-estado");
  43.     var idVi = this.getAttribute("data-ide");
  44.    
  45.     $.ajax({
  46.         url: "votosbtn.php",
  47.         type: "POST",
  48.         data: {
  49.             id: idVi,
  50.             valor: estado
  51.         }
  52.         success: function(data) {
  53.                 $('.votobtn').html(data);
  54.             }
  55.     });
  56. }, false);
  57. <!-- fin ajax form-->
  58.  
  59. <mas pagina></pags>
  60. </body>
  61. </html>
votosbtn.php:

Código PHP:
Ver original
  1. $id = mysql_real_escape_string(strip_tags($_POST['id']));
  2.  $valor = mysql_real_escape_string(strip_tags($_POST['valor']));
  3.  
  4.  if(!strcmp($valor, "like"){
  5.  $sql_votos=('UPDATE videos SET nvotos=nvotos+1, likes=likes+1 WHERE id="'.$id.'"');
  6.  $votos = mysql_query($sql_votos, $conexionbd) or die(mysql_error());
  7.  }
  8.  if(!strcmp($valor, "dislike"){
  9.  $sql_votos=('UPDATE videos SET nvotos=nvotos+1, dislikes=dislikes+1 WHERE id="'.$id.'"');
  10.  $votos = mysql_query($sql_votos, $conexionbd) or die(mysql_error());
  11.  }
  12.  
  13. echo "¡Gracias por votar! id='$id'";