goLogin
  • Home
  • Tasks
  • Settings
  • Home
  • QA
  • Components
  • 1. Login
  • 2. Query
  • 3. Invite
  • Hub go4webdev
go4webdev
1. Send url via fetch to the Web server
Browser

An url is sent via Javascript to the Go server. The response is either injected into a Go template or sent back to the fetch command as HTML for injecting into innerHTML (below).

// send to Go endpoint and display in innerHTML
function get_rec(id) {
  let url = "/" + module + "/view/" + id
  fetch(url, {
    headers: {
      "Content-Type": "application/json"
    },
    credentials: "same-origin"
  })
  .then((res) => res.text())
  .then((response) => {
    document.querySelector("aside").innerHTML = response;
  })
  .catch((error) => alert("Error get_rec:", error));
}