Converting classic asp to javascript: How to write or make returned string (json+ld) visible in header of webpage using javascript?

I have this Classic Asp code in header section of webpages:

<%
dim url, param, avgrate, votes, p, s
 url = "https://au2mailer.com/api/a2m-getschemaorg.asp"
 param = "?apikey=fe9fc289c3ff0af142b6d3bead98a923"
 Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
 HttpReq.SetOption(2) = 8192
 HttpReq.open "GET", url & param, false
 HttpReq.setRequestHeader "Content-Type", "application/json"
 HttpReq.Send()
 if (HttpReq.status = 200) Then
   response.write(HttpReq.responseText)
 end if
%>

and it works and is accepted by Google Schema Markup Validator.
Page to check https://carmagic.dk/online-bil-forretning-hvordan.asp
(Danish website)
I need to change the code so that it works whether the page is html, asp, aspx or php and my idea was to change it to javascript.
I have tried this javascript in header section

  <script>
      var request = new XMLHttpRequest();
        request.open('GET', 'https://au2mailer.com/api/a2m-getschemaorg.asp?apikey=fe9fc289c3ff0af142b6d3bead98a923');
        request.send();
        request.onload = ()=>{
          var receivedDom = new DOMParser().parseFromString(request.response, "text/html");
          var jsonstr = receivedDom.body.innerText;
          document.write(jsonstr);
        }
  </script>

The code execute but it does not work as the classic asp code!
Is my classic asp code not possible in javascript?

Thank you in advance and nice weekend

Michael Fiil