Using Javascript to display text from file on server

This is a example of how to get a file from the same domain using Javascript.

It’s simple but works.

<!DOCTYPE html>
<p id="demo">Fetch a file to change this text.</p>


async function getText(file) {
  let myObject = await fetch(file);
  let myText = await myObject.text();
  document.getElementById("demo").innerHTML = myText;


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.