When I call function CallMe, I get a result from service but my HTML element has text undefined, because of service is still loading data. I try async, await on Test() but no results. I want this to be pure JS. What I do wrong?
CallMe(){
document.getElementById('testId').InnerHTML = Test();
}
function Test(){
var request = new XMLHttpRequest(); // Create a request variable and assign a new XMLHttpRequest object to it.
request.open('GET', 'https://some service'); // Open a new connection, using the GET request on the URL endpoint
request.send();
request.onload = async function () {
var data = await JSON.parse(this.response);
return data[0][0][0];
}
}