Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/04/2012, 05:43
edie8
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 13 años, 3 meses
Puntos: 10
problemas con un archivo ajax

Buenas
tengo un archivo que hace una conexion con la base de datos cada vez que hay algo nuevo me lo muestra en seguida en la web pero al ponerlo donde lo quiero usar me aparecen 2 veces la imagen donde estan los comentarios y en este div donde muestra los comentarios me los muestra encima de la imagen, os dejo una imagen para que se vea mejor.
http://redsocial.16mb.com/Dibujo.bmp
esto lo hace este archivo:
Código PHP:
Ver original
  1. var xmlhttp = function()
  2. * * {
  3. * * * * var a;try{a = new XMLHttpRequest();}
  4. * * * * catch(e){try{a = new ActiveXObject('Msxml2.XMLHTTP');}
  5. * * * * catch(e){try{a = new ActiveXObject('Microsoft.XMLHTTP');}
  6. * * * * catch(e){alert('Your browser doesn\'t support ajax');a=false;}
  7. * * * * }}return a;
  8. * * };*
  9. * * window.onload = function()
  10. * * {
  11. * * * * var a = new comet();
  12. * * };*
  13. * * var comet = function()
  14. * * {
  15. * * * * var a = new xmlhttp();
  16. * * * * a.open('post',window.location+"?"+Math.random()+"="+Math.random(), true);
  17. * * * * a.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  18. * * * * a.onreadystatechange = function()
  19. * * * * {
  20. * * * * * * if(a.readyState == 4)
  21. * * * * * * {
  22. * * * * * * * * document.getElementById('content1').innerHTML = a.responseText;
  23. * * * * * * * * window.setTimeout(function(){
  24. * * * * * * * * * * a = new comet();* * * * * * * * * *
  25. * * * * * * * * },1000);
  26. * * * * * * * *
  27. * * * * * * }
  28. * * * * };
  29. * * * * a.send('algo=algo');* * * * * * * *
  30. * * };
Tengo algo mal o porque me produce estos errores??
este es el archivo galeria:
Código PHP:
Ver original
  1. <?php
  2. include("header.php");
  3. if (!isset($_SESSION['logueado_usuario'])) {
  4.     include ("login.php");  
  5. }
  6.     else {  
  7.     $nombre =$_SESSION['logueado_nombre'];
  8.     $id_usuario=$_SESSION['logueado_id'];
  9. $obejeto=$_REQUEST['objeto'];
  10.  
  11. }
  12. include("privados/config.php");
  13. $id=$_GET['id'];
  14.  
  15. $resultados=mysql_query("select * from imagenes where id='$id' and id_logueado='$id_usuario'",$conexion) or
  16.   die("Problemas en el select:".mysql_error());
  17.   // obtengo el id de la notiica actual
  18. $id = $_GET['id'];
  19. // Obtengo el id de la noticia anterior
  20. $a = mysql_query("select max(id) from imagenes where id <".$id. " and id_logueado='$id_usuario'");
  21. $ida = mysql_result($a,0);
  22. // Obtengo el id de la noticia siguietne
  23. $b = mysql_query("select min(id) from imagenes where id >".$id. " and id_logueado='$id_usuario'");
  24. $idb = mysql_result($b,0);
  25. $a1 = mysql_query("select max(id) from imagenes where id_logueado='$id_usuario'");
  26. $ida1 = mysql_result($a1,0);
  27. // Obtengo el id de la noticia siguietne
  28. $b1 = mysql_query("select min(id) from imagenes where id_logueado='$id_usuario'");
  29. $idb1 = mysql_result($b1,0);
  30. // coloco los links
  31. ?><div align="center"><div align="right" id="pasar"><?php
  32. if($idb1!=""){
  33. echo "<a href=galeria.php?id=".$idb1."><img src='Img/primera.png'></a>";}
  34. if($ida!="")
  35. {
  36. echo "<a href=galeria.php?id=".$ida."><img src='Img/atras.png'></a>";
  37. }
  38. if($idb!="")
  39. {
  40. echo "<a href=galeria.php?id=".$idb."><img src='Img/siguiente.png'></a>";  
  41. }
  42. if($ida1!=""){
  43. echo "<a href=galeria.php?id=".$ida1."><img src='Img/ultimo.png'></a>";}
  44. ?></div><?php
  45. $comentarios=mysql_query("select * from comentario where id_foto='$id'",$conexion);
  46. while($comen=mysql_fetch_array($comentarios))
  47. {
  48.     $comentario=$comen['comentario'];
  49. }
  50.   while($fot=mysql_fetch_assoc($resultados))
  51. {
  52. $foto_nombre=$fot['nombre'];
  53. $titulo=$fot['titulo'];
  54. $fecha=$fot['fecha'];
  55. if(isset($idb) && !empty($idb))
  56. {
  57.  echo '<a href=galeria.php?id='.$idb.' title="siguiente"><img src="'.$foto_nombre.'"></a>';
  58.  echo '<br>';
  59.  echo $comentario;
  60. }
  61. else
  62. {
  63. echo '<img src="'.$foto_nombre.'">';
  64. echo '<br>';
  65. echo $comentario;
  66. }
  67. }
  68. echo "<br>";
  69. ?><div align="right" id="pasar" style="margin-top:-49%"><?php echo $fecha."<br>"; echo $titulo; ?></div><?php
  70. ?>
  71. <?php  
  72. if($_POST)    
  73. {
  74.     set_time_limit(0);      
  75.     header("Edge-control: no-store");  
  76.     sleep(0);
  77.     $notificaciones2=mysql_query("select * from comentario",$conexion);
  78.     while($rs=mysql_fetch_assoc($notificaciones2))
  79.     {
  80.     echo   $rs['comentario']."<br>";
  81.     }  
  82.      
  83.     mysql_close($conexion);    
  84.     exit();  
  85. }
  86. ?>
  87. <script type="text/javascript">
  88. function sapeartextarea(){
  89.     var nav=(document.all)?"%0D":"%0A"
  90.     var ref=document.getElementById("textarea")
  91.     textoarea=escape(ref.value)
  92.     lineas=textoarea.split(nav)
  93.     lin=lineas.length
  94.     if(lin>4){
  95.         ref.rows=lin
  96.         document.getElementById("clin").innerHTML=lin
  97.     }
  98. }
  99. document.onkeyup = function(){sapeartextarea()}
  100. </script>
  101. <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>
  102.         <script src='js/jquery.autosize.js'></script>
  103.         <script>
  104.             $(function(){
  105.                 $('textarea').autosize();
  106.             });
  107.         </script>
  108. <script language="JavaScript" type="text/javascript" src="ajax.js"></script>
  109. <html>
  110. <head>    
  111. </head>
  112. <body>
  113. <form name="comentarios" action="" method="post" onSubmit="enviarDatos(); return false">
  114. <input type="hidden" name="id_logueado" value="1">
  115. <input type="hidden" name="id_foto" value="1">
  116. <textarea rows="1" style="overflow:auto;" name="comenta"></textarea>
  117. <input type="submit" name="Submit" value="Grabar" />
  118. </form>
  119.     <div id="content1"></div>
  120. <script type="text/javascript" src="js/comet.js"></script>
  121. </body>
  122. </html>
  123. <br /></div>
Necesito alguna idea para poder repararlo, ya que antes de poner ese archivo todo funcionaba bien, gracias. un saludo.