Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/08/2010, 08:14
Avatar de sjam7
sjam7
 
Fecha de Ingreso: diciembre-2001
Ubicación: Guadalajara, Mexico
Mensajes: 3.672
Antigüedad: 22 años, 4 meses
Puntos: 16
Respuesta: Timer, ejecutar funcion despues de 5 segundos

yo tengo una funcion q cada 3 min(creo) checa si hay algun registro nuevo en una tabla usando ASP, AJAX y JS, te la paso tal cual a ver si te sirve:

Código Javascript:
Ver original
  1. <%if session("user_admin")<>"admin" and alertas=1 then%>
  2. <script type="text/javascript">  
  3.  var RequestObject = false;  
  4.  var Archivo = 'checa_pedidos.asp?n=<%=session("negocio")%>'; //directorio donde tenemos el archivo ajax.php  
  5.  window.setInterval("actualizacion_reloj()", 300000); // el tiempo X que tardará en actualizarse  
  6.    if (window.XMLHttpRequest) //  
  7.  RequestObject = new XMLHttpRequest();  
  8.  if (window.ActiveXObject)    
  9.    RequestObject = new ActiveXObject("Microsoft.XMLHTTP");  
  10.  function ReqChange() {  
  11.  // Si se ha recibido la información correctamente  
  12.    if (RequestObject.readyState==4) {  
  13.    // si la información es válida  
  14.    if (RequestObject.responseText.indexOf('invalid') == -1)  
  15.    {  
  16.    // obtener la respuesta  
  17.    var msgs = RequestObject.responseText.split('|');  
  18.    // Buscamos la div con id online  
  19.    //document.getElementById("online").innerHTML = msgs[0];  
  20.         if(msgs[0]>0){
  21.             //document.getElementById("pedidos_flash").style.visibility='visible';
  22.             document.getElementById("pedidos_flash").innerHTML = "<object style='z-index:-1' type='application/x-shockwave-flash' data='pedidos.swf' width='191' height='36'><param name='movie' value='pedidos.swf'><param name='wmode' VALUE='transparent'></object>";
  23.             alert("Tienes " + msgs[1] + " pedidos pendientes ");
  24.         }
  25.         else {
  26.             //alert("No tienes mensajes");
  27.             //document.getElementById("pedidos_flash").style.visibility="hidden";
  28.         }
  29.    }  
  30.    else {  
  31.    // Por si hay algun error  
  32.    //document.getElementById("online").innerHTML = "Error llamando";  
  33.             alert("Ha ocurrido un error");
  34.  
  35.    }  
  36.    }  
  37.    }  
  38.  function llamadaAjax() {  
  39.   // Mensaje a mostrar mientras se obtiene la información remota...  
  40.    document.getElementById("pedidos").innerHTML = "";  
  41.    // Preparamos la obtención de datos  
  42.    RequestObject.open("GET", Archivo , true);  
  43.    RequestObject.onreadystatechange = ReqChange;  
  44.    // Enviamos  
  45.    RequestObject.send(null);  
  46.    }  
  47.    function actualizacion_reloj() {  
  48.    llamadaAjax();  
  49.    }  
  50.  
  51.     var ancho=screen.width;
  52.     var alto=screen.availHeight;
  53.     var ventana;
  54.     var anchoVentanita=200;
  55.     var altoVentanita=150;
  56.     function cerrar(){if(ventana &&!ventana.closed){ventana.close()}}
  57.     function ventanita(url){
  58.     ventana=window.open(url,'ventanita','width='+anchoVentanita+',height=0,top='+alto+',left='+(ancho-anchoVentanita-10));
  59.     desplegar(true);
  60.     }
  61.     function desplegar(cambio){
  62.         if(cambio){
  63.             inicio=0;
  64.             fin=altoVentanita;
  65.             incremento=1;
  66.         }
  67.         else{
  68.             inicio=altoVentanita;
  69.             fin=0;
  70.             incremento=-1;
  71.         }
  72.         for(a=inicio;a!=fin;a+=incremento){
  73.             ventana.focus();
  74.             ventana.resizeTo(anchoVentanita,a);
  75.             ventana.moveTo((ancho-anchoVentanita-10),(alto-a));
  76.         }
  77.         if(cambio){
  78.             setTimeout('desplegar(false)',2000)
  79.         }
  80.         else{
  81.             ventana.close();
  82.         }
  83.     }
  84.  
  85. </script>
  86. <%end if%>