Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!