Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/08/2010, 13:44
Avatar de intiweb
intiweb
 
Fecha de Ingreso: mayo-2009
Ubicación: Capital Federal
Mensajes: 363
Antigüedad: 14 años, 11 meses
Puntos: 5
problemas con codigo ajax

hola estoy hacieno un sistema donde la gente comenta una fotos que otros usuarios comentan tipo las redes sociales.
y tiene un sistema en Ajax.
soy vastante nuevo en esto del ajax y no logro encontrar el error que tengo ya que en el mismo sistema tengo dos aplicaciones muy parecidas.
con una paso las fotos y con otra los comentarios.
cuando hise el primer sistema de las fotos todo bien funciono a la perfeccion, y cuando le agregue este otro sistema de los comentarios deja de funcionar

les paso el codigo completo a ver si alguien sabe donde esta el error

codigo ajax
Código:
function getXMLHTTPRequest (){
try {
req = new XMLHttpRequest();
}catch(err1){
       try {
	     req = new ActiveXObject("Msxml2.XMLHTTP");
	   }catch(err2){
	      try { req = new ActiveXObject("Microsoft.XMLHTTP");
	   }catch(err3){
	    req = false;
	  }
    } 
  }
  return req;
}

var miPeticion = getXMLHTTPRequest ();
var peticomentario = getXMLHTTPRequest ();

function prevxfoto()
{
var ids = document.miform.namefoto.value;
var miAleatorio=parseInt(Math.random()*99999999);
var url = "servidorfotoprev.php?id=" + ids;
miPeticion.open("GET", url+ "&rand=" + miAleatorio, true);
miPeticion.onreadystatechange = respuestaAjaxFoto;
miPeticion.send(null);
}
function nexfoto()
{
var ids = document.miform.namefoto.value;
var miAleatorio=parseInt(Math.random()*99999999);
var url = "servidorfoto.php?id=" + ids;
miPeticion.open("GET", url+ "&rand=" + miAleatorio, true);
miPeticion.onreadystatechange = respuestaAjaxFoto;
miPeticion.send(null);
}

function respuestaAjaxFoto() {
if(miPeticion.readyState == 4) {
if(miPeticion.status == 200) {
 var datolink = miPeticion.responseXML.getElementsByTagName("link")[0];
 var datonamefoto = miPeticion.responseXML.getElementsByTagName("fotoname")[0];
 var datoid = miPeticion.responseXML.getElementsByTagName("id")[0];
 var textolink = datolink.childNodes[0].nodeValue;
 var textoid = datoid.childNodes[0].nodeValue;
 var textonamefoto = datonamefoto.childNodes[0].nodeValue;
 document.getElementById('foto').innerHTML = ("<a href=\"javascript:;\" onclick=\"nexfoto();\"><img src=\"" + textolink + "\" width=\"600\"></img></a>");			
 document.getElementById('namefoto').innerHTML = ("<input type=\"hidden\" id=\"namefoto\" value=\"" + textoid + "\"></form>");
 document.getElementById('actual').innerHTML = (textonamefoto);
 document.getElementById('nombrefoto').innerHTML = (textonamefoto);
			


        } else {
		alert("Ha ocurrido un error: " + miPeticion.statusText);
        }
    } else {     // si readyState ha cambiado
                 // pero readyState <> 4
           document.getElementById('foto').innerHTML = '<img src="jpg/cargador.jpg">';
    }

}

function comentariofoto()
{
var idss = document.miform.namefoto.value;
var comentario = document.comentariofoto.comentario.value;
var usuario = document.comentariofoto.username.value;
var miAleatorio=parseInt(Math.random()*99999999);
var url = "servidorcomentario.php?id=" + idss +"&comentario=" + comentario +"&username=" + usuario;
peticomentario.open("GET", url+ "&rand=" + miAleatorio, true);
peticomentario.onreadystatechange = respuestaAjaxComentario;
peticomentario.send(null); 
}

function respuestaAjaxComentario() {
if(peticomentario.readyState == 4) {
if(peticomentario.status == 200) {

 var datouser = peticomentario.responseXML.getElementsByTagName("usuario");
 var datocomentario = peticomentario.responseXML.getElementsByTagName("comentario");
 var datofecha = peticomentario.responseXML.getElementsByTagName("fecha");
 var datohora = peticomentario.responseXML.getElementsByTagName("hora");
 
 $a = 1;
 for ($a==1; $a<=4; $a++)
 {
 var textouser = datouser.childNodes[$a].nodeValue;
 var textocomentario = datocomentario.childNodes[$a].nodeValue;
 var textofecha = datofecha.childNodes[$a].nodeValue;
 var textohora = datohora.childNodes[$a].nodeValue;
 
 var resultadofinal = resultadofinal + "<table width=\"75%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#A7C4D2\">
         <!--DWLayoutTable-->
         <tr>
         <td width=\"4\" height=\"5\"></td>
         <td width=\"20\"></td> 
         <td width=\"20\"></td>
         <td width=\"20\"></td>
         <td width=\"20\"></td>
          </tr>
          <tr>
         <td width=\"20\" height=\"60\" >&nbsp;</td>
         <td valign=\"top\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#000000\">
         <!--DWLayoutTable-->
          <tr>
         <td width=\"40\" height=\"40\" valign=\"top\"><a href=\"muro.php?name="+textouser+"\"> <img src=\"fotos/usuarios/"+textouser+".jpg\" width=\"40px\" height=\"40px\" bordercolor=\"#FFFFFF\" border=\"0\" ></img> </a> </td>
         </tr>
          </table></td>
         <td>&nbsp;</td>
         <td valign=\"top\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
         <!--DWLayoutTable-->
         <tr>
         <td width=\"296\" height=\"65\"><table width=\"296\" cellspacing=\"2\">
         <tr>
         <td width=\"110\"><div align=\"left\"><span class=\"Estilo1\">&nbsp; "+textouser+"</span></div></td>
         <td width=\"174\" bgcolor=\"#FFFFFF\"><div align=\"left\"><span class=\"Estilo3\">&nbsp;<a href=\"perfil.php?name="+textouser+"\">Ver Perfil</a> <a href=\"documentos.php?name="+textouser+"\">Documentos</a></ span></div>
	     </span></td>
         </tr>
         <tr>
         <td height=\"40\" colspan=\"2\" bgcolor=\"#FFFFFF\"><div align=\"left\">&nbsp;<span class=\"Estilo4\">"+textocomentario+"<br></span><span class=\"Estilo8\">"+textofecha+" - "+textohora+"<br></span> </div></td>
         </tr>
         </table></td>
         </tr>
       </table>
        </td>
         <td>&nbsp;</td>
        </tr>
        <tr>
        <td height=\"4\"></td>
         <td></td>
         <td></td>
          <td></td>
         <td></td>
         </tr>
        </table>";
		
 
 }
 
 document.getElementById('comentarios').innerHTML = ("hola");
			


        } else {
		alert("Ha ocurrido un error: " + peticomentario.statusText);
        }
    } else {     // si readyState ha cambiado
                 // pero readyState <> 4
           document.getElementById('comentarios').innerHTML = 'laouen';
    }

}
codigo php
Código PHP:
include("fns.php");
include("loops.php");

header('Content-Type: text/xml');
echo "<?xml version="1.0\" ?>";
echo 
"<comentarios>";

        
$db_conn db_connect();

     
$username $_GET['username'];
     
$id $_GET['id'];
     
$comentario $_GET['comentario'];
     
$year date("Y");
     
$mes date("m");
     
$dia date("d");
     
$hora date("H");
     
$minuto date("i");
     
$segundo date("s");
     
     
$insertcomentario "insert into comentarios_fotos values ('".$id."', '".$username."', '".$comentario."', '".$year."', '".$mes."', '".$dia."', '".$hora."', '".$minuto."', '".$segundo."')";
     
$resultinsert mysql_query($insertcomentario$db_conn) or die (mysql_error());
     
     
$querycomentario "select * from comentarios_fotos where id = '$id'";
     
$resultcomentario mysql_query ($querycomentario$db_conn) or die (mysql_error());
     
$numcomentario mysql_num_rows($resultcomentario);
     
     if (
$numcomentario>0)
     {
          while (
$array mysql_fetch_array($resultcomentario))
          {
             
$user $array['usuario'];
             
$comentario $array['comentario'];
             
$fecha $array["dia"]."-".$array["mes"]."-".$array["year"];
             
$hora $array["hora"].":".$array["minuto"].":".$array["segundo"]." Hs:";
             
             echo 
"<usuario>$user</usuario>
                   <comentario>$comentario</comentario>
                   <fecha>$fecha</fecha>
                   <hora>$hora</hora>"
;  
          }
     }
     
     
        echo 
"</comentarios>";
no se porque deja de funcionar cuando al codigo ajax le agrego las funciones:
respuestaAjaxComentario() y comentariofoto()
que son las que se encargan del comentario.
el php me fije aparte y procesa bien los datos.

bueno si alguien sabe cual es mi error porque yo no