0

I have a web server (thttpd), and I want to periodically change the text on the HTML page depending on the data from my application C. I think to write a simple .txt file in the C application and periodically read it on a web server and change data on the HTML page. But I don't know how to do it. Maybe there are more correct and simple versions, how to do it?

ANSWER: I make this by using fetch(). This code read text from file dynamic_data.txt and change element with id="ispr_1" with this text every 3sec.

<script>

    const ispr = document.getElementById("ispr_1");

    var myFile = 'dynamic_data.txt';
    async function getUsers() {
        var response = await fetch(myFile, {cache: "reload"});
        if (response.ok) {
            var data = await response.text();
            ispr.textContent = data;
            return data;
        } else {
            alert('error', response.status);
        }
    }

    var intervalId = setInterval(getUsers, 3000);
</script>
1
  • General design questions like this are inappropriate for SO. You need to write code and ask specific questions if you can't get it working. Commented Oct 29, 2021 at 15:02

1 Answer 1

0

Put your C file output somewhere in your server, and look at https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.