Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/10/2012, 12:39
Avatar de maximendez88
maximendez88
 
Fecha de Ingreso: septiembre-2012
Ubicación: Montevideo
Mensajes: 131
Antigüedad: 11 años, 7 meses
Puntos: 3
Sonrisa listado de ajax que vaya refrescando de a un solo registro

hola...tengo un listado en php que lo traigo con ajax, cada vez que guardo un registro en una base de datos... Este listado muestra un boton. el cual debería desaparecer cada vez que lo presiono. Hasta ahi va todo bien, el problema está en que cuando vuelvo agregar datos, se genera nuevamente todo el listado y por ende se generan todos los botones nuevamente. Hay alguna forma de agregar solo el último valor en el listado? asi no se generan todos los botones nuevamente... Dejo mi codigo para ver si alguien me puede dar una mano... saludos...


este es el php que muestra las ciudades y el boton.
circuit_actual.php
Código PHP:
Ver original
  1. <?php
  2. include "config.php";
  3. $nombrecir=$_SESSION['namecirc'];
  4. $query = "SELECT city, arrival,departure FROM `sites` WHERE nombreCirc='".$nombrecir."'";
  5. $result = mysql_query($query);
  6. $numero = 0;
  7. ?>
  8. <style type="text/css">
  9.     .listado td{
  10.         width:25%;
  11.         font-family:verdana;
  12.     }
  13. </style>
  14. <table class="listado">
  15. <?php
  16. $row = mysql_fetch_array($result);
  17.  
  18. ?>
  19.     <tr>
  20.     <td>
  21.         <b><?php echo $row["city"]?></b><br/>
  22.         Arrival:<?php echo $row["arrival"]?><br/>
  23.         Departure:<?php echo $row["departure"]?><br/>
  24.       <?php
  25. while($row2 = mysql_fetch_array($result))
  26. {
  27. ?>
  28.     <tr>
  29.     <td>
  30.           <a title="TripMinded - Add Transport" id="transportelink" href="addtransport.php" class="ajax cboxElement">
  31.         <input type="button" value="Add Transport"  onclick="this.style.display='none'" id="algo"  /></a>
  32.    
  33.     <br/>
  34.         <b><?php echo $row2["city"]?></b><br/>
  35.         Arrival:<?php echo $row2["arrival"]?><br/>
  36.         Departure:<?php echo $row2["departure"]?><br/>
  37.     </td>
  38.     </tr>
  39. <?php
  40.     $numero++;
  41. }
  42. ?>
  43.     </td>
  44.     </tr>
  45. </table>
  46. <?php  
  47. ?>

y aca esta el ajax
Código Javascript:
Ver original
  1. function objetoAjax(){
  2.  var xmlhttp=false;
  3.  try {
  4.   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  5.  } catch (e) {
  6.   try {
  7.    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  8.   } catch (E) {
  9.    xmlhttp = false;
  10.   }
  11.  }
  12.  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  13.   xmlhttp = new XMLHttpRequest();
  14.  }
  15.  return xmlhttp;
  16. }
  17.  
  18. function save() {
  19. ajax=objetoAjax();
  20. ajax.onreadystatechange=function() {
  21. if (ajax.readyState==4 && ajax.status==200) {
  22. alert("city added successfully");
  23. listar();
  24.   }
  25.  }
  26. var cityvalue=encodeURIComponent(document.getElementById('city').value)
  27. var arrivalvalue=encodeURIComponent(document.getElementById('datepicker_value').value)
  28. var departurevalue=encodeURIComponent(document.getElementById('otrodatepicker_value').value)
  29. var commentvalue=encodeURIComponent(document.getElementById('comment').value)
  30. if(arrivalvalue>departurevalue)
  31. {
  32.     alert('Day of arrival can not be after a day of departure');
  33. }
  34. else if(departurevalue<arrivalvalue)
  35. {
  36.     alert('Day of departure can not be until the arrival day');
  37. }
  38. else{  
  39.   $('#example-placeholder').html('<p><img src="ajax-loader.gif" width="220" height="19" /></p>');
  40.  setTimeout("$('#example-placeholder').hide();", 5000);
  41.   ajax.open("GET", "addCity.php?city="+cityvalue+"&arrival="+arrivalvalue+"&departure="+departurevalue+"&comment="+commentvalue,true);
  42.   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  43.   //enviando los valores
  44.   ajax.send()  
  45.   document.getElementById('savecity').disabled = true;
  46.   document.getElementById('more').disabled = true;
  47.   document.getElementById('ciudad').value = "Select other city";
  48.   document.getElementById('add').disabled = false;  
  49.   document.getElementById('inner').style.display="block";
  50.   document.getElementById('datepicker_value').value='';
  51.   document.getElementById('otrodatepicker_value').value='';
  52.   document.getElementById('comment').value='';
  53.   document.getElementById('close').disabled=false;
  54. }
  55. }
  56.  
  57. function listar(){
  58.   var ajax2 = objetoAjax();
  59.   ajax2.open("POST", "circuit_actual.php",true);
  60.   ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  61.   ajax2.send(null);
  62.   ajax2.onreadystatechange=function() {
  63.   if (ajax2.readyState==4 && ajax2.status==200)
  64.  {                 
  65.         document.getElementById('capa').innerHTML = ajax2.responseText;            
  66.  }
  67.  }
  68.            
  69.  }

Última edición por maximendez88; 24/10/2012 a las 13:46