Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/06/2013, 16:49
alexg88
 
Fecha de Ingreso: abril-2011
Mensajes: 1.342
Antigüedad: 13 años
Puntos: 344
Respuesta: 2 ajax no funcionan

No puedes asignar el evento onload dos veces, porque sólo queda la última vez que lo asignas.

Código Javascript:
Ver original
  1. <script>
  2.     function encontrarnumero(){ //este es el ajax
  3.        
  4.         var divid='u219-4';
  5.  
  6.         if (window.XMLHttpRequest)
  7.         {// code for IE7+, Firefox, Chrome, Opera, Safari
  8.             xmlhttp=new XMLHttpRequest();
  9.         }
  10.         else
  11.         {// code for IE6, IE5
  12.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  13.         }
  14.         xmlhttp.onreadystatechange=function()
  15.         {
  16.             if (xmlhttp.readyState===4 && xmlhttp.status===200)
  17.             {
  18.                 document.getElementById(divid).innerHTML=xmlhttp.responseText;
  19.                 setInterval(encontrarnumero,1000);
  20.  
  21.  
  22.             }
  23.         };
  24.         xmlhttp.open("GET","numero.php?q="+q+"&p="+p+"&w="+w,true);
  25.         xmlhttp.send();
  26.     }
  27.  
  28.     function encontrartiempo(){ //este es el ajax
  29.        
  30.         var divid='tiempo';
  31.  
  32.  
  33.         if (window.XMLHttpRequest)
  34.         {// code for IE7+, Firefox, Chrome, Opera, Safari
  35.             xmlhttp=new XMLHttpRequest();
  36.         }
  37.         else
  38.         {// code for IE6, IE5
  39.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  40.         }
  41.         xmlhttp.onreadystatechange=function()
  42.         {
  43.             if (xmlhttp.readyState===4 && xmlhttp.status===200)
  44.             {
  45.                 document.getElementById(divid).innerHTML=xmlhttp.responseText;
  46.                 setInterval(encontrartiempo,2000);
  47.  
  48.  
  49.             }
  50.         };
  51.         xmlhttp.open("GET","tiempo.php?q="+q+"&p="+p+"&w="+w,true);
  52.         xmlhttp.send();
  53.     }
  54.  
  55.  
  56.     window.onload=function(){
  57.         encontrarnumero();
  58.         encontrartiempo();
  59.     };
  60. </script>

Te recomiendo aun así que uses jquery u otra librería que facilita muchos las llamadas ajax o si no quieres, create una función para reutilizar el código repetido.

Un saludo.