Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
JavaScript Array can't updating in real time

I write the following code to try to get an array from the background using XMlHttpRequest:

var temp = new Array();
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', url, true);
httpRequest.send(JSON.stringify(choose + "#" + input + "#"));
httpRequest.onreadystatechange = function() {
    var message = httpRequest.responseText;
    var temps = message.split("#");
    for (var i = 0; i < temps.length; i++)
        temp.push(temps[i]);
}
console.log(temp[0]);
console.log(temp.length);

But the first time I execute it, it returns me length=0 and temp[0]=undefined; When I execute it the second time, it returns me the correct length and temp[0],it looks like the first time didn't execute at all. What's the problem and how should I deal with it?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda