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

86
Views
how to read the variable present in the function of an XMLHttpRequest object outside the function

I have the function shown in the code below, I need to read the value of myArr outside the function.

var xmlhttp = new XMLHttpRequest();
var url = "https://xzssgkuhg7.execute-api.us-east-2.amazonaws.com/items/aabbccdd234"; 

xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
   var myArr = JSON.parse(this.responseText);
   document.getElementById("id01").innerHTML = this.responseText;
  }
};


xmlhttp.open("GET", url, true);
xmlhttp.send();

I tried defining the variable outside the function but it is undefined. How can I do?

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!