Ver Mensaje Individual
  #12 (permalink)  
Antiguo 03/02/2012, 07:16
edie8
 
Fecha de Ingreso: noviembre-2011
Mensajes: 516
Antigüedad: 12 años, 5 meses
Puntos: 10
Respuesta: consulta con ajax y php

Estoy probandolo pero no me funciona cuando lo incorporo a mi web mira este es el codigo
index.php
Código PHP:
<?php include("header.php"); 

if (!isset(
$_SESSION['logueado_usuario'])) { 
    include (
"login.php");  
echo 
"<a href='registro.php'>Registrarse</a>" ;} 
    else {  
    
$nombre =$_SESSION['logueado_nombre']; 
    
$id_usuario=$_SESSION['logueado_id']; 
?> 
 <script src="ajax.js"></script>
<?php
include("privados/config.php");
$registros=mysql_query("select * from usuarios WHERE id = '$id_usuario'"$conexion)or
  die(
"Problemas en el select:".mysql_error());
  while(
$reg=mysql_fetch_array($registros))
  {
  
?><div id="izquierda">
  <div class="nombre"><? echo $nombre?></div>
<div class="img_usuario"> <img src="<?php echo "".$reg['imagen']. "";?>" /></div> 
<div id="notificaciones"></div>
<div class="amigos_agregados"></div></div> 

<?php
  
}
?>

 <div class="contenedor_muro"> 
¿Que estas pensando? 
     <form name="form" method="post" > 
     <textarea cols="30" rows="2" name="textarea_noticia" class="textarea_noticia" id="textarea_noticia"></textarea><br /> 
     <input type="submit" value="Compartir" class="enviar_noticia" /> 
     </form> 
</div> 

<div id="cargando"></div> 

<div id="mostrar"></div> 
<?php

include("consulta.php"); 




// cerramos el else 

include ("footer.php");  
?>
ajax.js
Código PHP:
var seconds 1// el tiempo en que se refresca
    
var divid "notificaciones"// el div que quieres actualizar!
    
var url "registro1.php"// el archivo que ira en el div

    
function refreshdiv(){

        
// The XMLHttpRequest object

        
var xmlHttp;
        try{
            
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
        
}
        catch (
e){
            try{
                
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
            
}
            catch (
e){
                try{
                    
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (
e){
                    
alert("Tu explorador no soporta AJAX.");
                    return 
false;
                }
            }
        }

        
// Timestamp for preventing IE caching the GET request
        
var timestamp parseInt(new Date().getTime().toString().substring(010));
        var 
nocacheurl url+"?t="+timestamp;

        
// The code...

        
xmlHttp.onreadystatechange=function(){
            if(
xmlHttp.readyState== && xmlHttp.readyState != null){
                
document.getElementById(divid).innerHTML=xmlHttp.responseText;
                
setTimeout('refreshdiv()',seconds*1000);
            }
        }
        
xmlHttp.open("GET",nocacheurl,true);
        
xmlHttp.send(null);
    }

    
// Empieza la función de refrescar

    
window.onload = function(){
        
refreshdiv(); // corremos inmediatamente la funcion
    

registro1.php
Código PHP:
<?php
echo "probando el refrescado del div";
?>
os ice caso lo ice con ajax pero funciona cuando ago la prueba en otra pagina si la ago en esta no funciona nose en que fallo me pueden ayudar. gracias.

Última edición por edie8; 03/02/2012 a las 07:31