let request = new XMLHttpRequest();
let data;
request.open('POST', "https://example.page");
request.setRequestHeader(not important);
request.setRequestHeader(not important);
request.setRequestHeader(not important);
request.onreadystatechange = function () {
if (this.readyState === 4) {
data = this.responseText;
}
};
const body = '{some values}';
request.send(body);
var test = data; <-- test ends up being undefined
How can I use the value I get from the response text outside the function? I tried to do this with a callback function, but that didn't really work out.
I'm kinda new to javascript and I would really appreciate some help :)