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

150
Vistas
How to wait unitl xhr finished?

I'm making a website where I need to get all people who are registered to an event but every time I make the xhr request the code execute and do not wait the xrh response, that's cause a lot of trouble in the following code...

let inscrit = new XMLHttpRequest();
let methode = "GET";
let url = "php/getInscrit.php";
let asynchronous = true;

inscrit.open(methode, url, asynchronous);
inscrit.timeout = 4000;
inscrit.onload = function () {
  let people;

  if (this.readyState == 4 && this.status == 200) {
    people = JSON.parse(this.responseText);
  }
};
inscrit.send(null);
return people;

Sorry for my bad English and ty

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It seems like the problem is in "onload", which is only called one time, which could be right at the beginning before it's fully loaded, instead you should do everything in the onreadystatechange callback, so for example:

  let inscrit = new XMLHttpRequest();
    let methode = "GET";
    let url = "php/getInscrit.php"
    let asynchronous = true;

    inscrit.open(methode, url, asynchronous);
    inscrit.timeout = 4000;
    inscrit.onreadystatechange = function() {


        let people ;

        if (this.readyState == 4 && this.status == 200) {

            people = JSON.parse(this.responseText);


        }
    }
    inscrit.send(null);
    return people ;
about 4 years ago · Juan Pablo Isaza Denunciar
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