Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/06/2013, 19:35
jbarranco9
 
Fecha de Ingreso: abril-2013
Mensajes: 4
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: 2 ajax no funcionan

Muchas gracias a los que respondieron, efectivamente el problema era que no podía hacer 2 veces window.onload... finalmente la solución fue hacer una función. la dejo a continuación por si alguien tiene el mismo problema:

Código:
<script>
// Move repeating code to a function
function doAJAX(divid, page) {
    if (window.XMLHttpRequest) {
        // Use `var` when declaring variables
        var xmlhttp = new XMLHttpRequest();
    } else {
        var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            document.getElementById(divid).innerHTML = xmlhttp.responseText;

            // Use `setTimeout` if you're going to make recursive calls!
            setTimeout(function() {
                doAJAX(divid, page)
            }, 1000);
        }
    };
    xmlhttp.open("GET", page + "?q=" + q + "&p=" + p + "&w=" + w, true);
    xmlhttp.send();
}

// Just one onload handler that calls the function twice,
//    passing the different info for each call
window.onload = function () {
    doAJAX('u219-4', "numero.php");
    doAJAX('tiempo', "tiempo.php");
};
</script>