Fetch partial in javascript

How do I fetch a partial inside the JS in the code below where it says “partial goes here”? The partial has HTML and Hugo syntax in it. I am using the code in single.html file

<button id="drop" class="drop">Toggle Comments</button>
      <article class="comment" id="comment">
   <!-- partial content goes here -->
      </article>
      <script type="text/javascript">
          document.querySelector('#drop').addEventListener('click', 
  () => fetch('PARTIAL GOES HERE')
    .then(res => res.text())
    .then(data => document.querySelector('#comment').innerHTML = data))
      </script>

(Is this really possible? Or it is a server-side thing?)

It’s possible, but I’m not sure I would want to do it. I Probably would go the JSON route. But whatever you want to fetch ned to be available as an URL. One simple route to this is to put it (or mount it) inside /static.

And how do you fetch it, with which URL?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.