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

157
Vistas
javascript: http-response into frontend

I have a programm in React that

does a http-request during componentWillMount and sets a variable response on the response of the http-request

var response = "";
class App extends Component{
  componentWillMount(){
     var myRequest = new XMLHttpRequest(),
        method = 'GET',
        url = //url; 
      myRequest.open(method, url, true);
      myRequest.send();
      myRequest.onload = function() {
        response = myRequest.response;
    };

and that displays the response in the method render() by using the "response" variable.

However, this is not working -> the initial value "" is displayed. The HTTP-Request is working (tested), the HTTP-Response is recieved and correct(also tested), so perhaps the program is just not waiting untill the http request is done and instead takes the initial value for "response".

How can i fix this, i.e. how can i enforce that response is set to the HTTP-response?

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