从后端服务器获取数据并在客户端HTML网站上显示它

huangapple go评论68阅读模式
英文:

Getting data from a backend server side file and displaying it on a client side html site

问题

我有一个 AWS 服务器,持续在后台运行一个程序来更新一个 txt 文件。我想要使用最新的文件数据进行计算,并在一个 HTML 页面上显示它。

(我还将使用 systemctl 在服务器上托管 HTML)


我尝试使用 fs,但似乎无法访问,因为它是客户端侧的,我也尝试搜索我所处的情况,但找不到相关信息。

(注意:这是我第一次尝试这样的操作,并且使用服务器,所以不确定我可以/不能做什么)

英文:

I have an AWS server that continually runs a program on the background updating a txt file. I want to make calculations with the latest file data and display it on an html page.

(I will also be using systemctl to host the html on the server)


I tried using fs but it's just not possible to access since it's a client side I think, I also tried searching for the situation I'm in but just can't find anything on it.

(Note: First time trying something like this and using a server so not sure what I can/can't do)

答案1

得分: 1

I think AJAX can help you, fetch function to be more specific.

I suggest following solution.

If this script works on your server, you can make an asynchronous function in JavaScript that will fetch data from the server once in a while and then, using JS, update the table on the frontend.

Or, as It was suggested in comments - use WebSockets with its JavaScript API.

英文:

I think AJAX can help you, fetch function to be more specific

I suggest following solution

If this script works on your server you can make asynchronous function in javascript, that will fetch data from server once in a while and then using JS update table on frontend

Or, as It was suggested in comments - use WebSockets with its JavaScript API

huangapple
  • 本文由 发表于 2023年8月4日 05:57:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76831817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定