[英]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.我有一个网络服务器 (thttpd),我想根据我的应用程序 C 中的数据定期更改 HTML 页面上的文本。我想在 C 应用程序中编写一个简单的 .txt 文件并定期在网络上读取它服务器并更改 HTML 页面上的数据。 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:我使用了 Nicolas 的建议,并尝试使用 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.我不知道 JS,我只是尝试使用示例。
将您的 C 文件输出放在服务器中的某个位置,然后查看https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.