I'm quite new to JS and i have a problem. I'm trying to get XMLHttpRequest.responseText to use it as variable in GTM. The url I'm sending request is an endpoint.
function httpGetAsync (url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
callback(xmlHttp.responseText);
}
}
xmlHttp.send();
}
httpGetAsync("https://www.example.pl/example-uid-cookie", function(response) {
console.log(response);
});
The answear I'm getting looks like below and I would like to have the value instead of undefined: