简体   繁体   中英

Dynamically change text on HTML page from the С program

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?

I used advice from Nicolas, and try use XMLHTTPRequest:

<script>
function readTextFile(file)
{
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                var allText = rawFile.responseText;
                alert(allText);
            }
        }
    }
    rawFile.send();
}

var intervalId = setInterval(readTextFile(cgi-bin/dynamic_data.txt), 5000);
</script>

But this code doesn't work. I dont know JS, i just try to use examples.

将您的 C 文件输出放在服务器中的某个位置,然后查看https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM