-4

Maybe that's easy, but I cannot find any solution. I have an endpoint, which accepts POST requests with specific values and returns HTML. How should I properly do this request to show received HTML in browser?

In simple english, I'd like to have something like <a> tag, but with specified http method, headers etc. used during clicking on it.

Karol Selak
  • 4,248
  • 6
  • 35
  • 65

1 Answers1

1

This is one way to do it.

fetch(url)
    .then(res => res.text())
    .then((html) => {
        // change the content of an element to the html received
        el.innerHTML = html

        // append the html to the body
        document.body.innerHTML += html;
    })
kevguy
  • 4,328
  • 1
  • 24
  • 45