Ver Mensaje Individual
  #15 (permalink)  
Antiguo 28/06/2015, 10:30
Avatar de Eleazan
Eleazan
 
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: quiero agregar un perfil con foto y datos de usuario

Cita:
Iniciado por xfxstudios Ver Mensaje
este codigo envia la peticion sin recargar:
Código Javascript:
Ver original
  1. <script language="javascript" type="text/javascript">
  2.   var RequestObject = false;
  3.    //directorio donde tenemos el archivo ajax.php
  4.   var Archivo = 'mensajes/contador.php?rif=<?php echo $row_datos_nuevo['rif']; ?>&usuario=<?php echo $row_datos_nuevo['usuario']; ?>&unidad=<?php echo $row_datos_nuevo['unidad_explot']; ?>';
  5.   // el tiempo X que tardará en actualizarse
  6.   window.setInterval("actualizacion_reloj()", 30000);
  7.   if (window.XMLHttpRequest) RequestObject = new XMLHttpRequest();
  8.   if (window.ActiveXObject) RequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  9.   function ReqChange() {
  10.   // Si se ha recibido la información correctamente
  11.     if (RequestObject.readyState==4) {
  12.      // si la información es válida
  13.      if (RequestObject.responseText.indexOf('invalid') == -1) {
  14.      // Buscamos la div con id online
  15.        document.getElementById("online").innerHTML = RequestObject.responseText;
  16.      } else {
  17.       // Por si hay algun error document.getElementById("online").innerHTML = "Error llamando";
  18.      }
  19.     }
  20.   }
  21.   function llamadaAjax() {
  22.         // Mensaje a mostrar mientras se obtiene la información remota...
  23.     document.getElementById("online").innerHTML = "";
  24.     // Preparamos la obtención de datos
  25.     RequestObject.open("GET", Archivo+"?"+Math.random() , true);
  26.     RequestObject.onreadystatechange = ReqChange;
  27.     // Enviamos
  28.     RequestObject.send(null);
  29.   }
  30.   function actualizacion_reloj() {
  31.    llamadaAjax();
  32.  }
  33. </script>
Si utilizas jQuery....

¿Pq no usas la función $.get() (o bien, $.post o $.ajax !) ? Queda bastante más limpia que todo eso ;)

Saludos!
__________________
>> Eleazan's Source
>> @Eleazan