简体   繁体   中英

XHR request response is an HTML object. How can I keep it and display it the way it is?

I have a server-side xQuery which transforms an XML file into an HTML document. I want to send a request behind the scenes to that xQuery, get the HTML back, and inject it in my page, obviously retaining all the structure as it is without parsing it or traversing the nodes again.

        function loadXSLtoHTML () {
             document.getElementById('xslt-transformation').innerHTML = this.respinseXML
           }
           
           var oReq = new XMLHttpRequest();
           oReq.addEventListener("load", loadXSLtoHTML);
           
           oReq.open("GET", "xquery generating HTML");
           oReq.responseType = "document";
           oReq.send();

I know about the limitations of XHR calls. Is there really not a way of keeping my response HTML and injecting it as it is?

Thanks to this answer , I solved with fetch() :

const url = my transformation URL";
fetch(url)
  .then(
    response => response.text()
  ).then(
    text => document.getElementById('xslt-transformation').insertAdjacentHTML('beforeend', text)
  );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM