gpt4 book ai didi

戈朗 : Automatic Refresh of a HTTP Page

转载 作者:数据小太阳 更新时间:2023-10-29 03:33:33 28 4
gpt4 key购买 nike

我有一个使用 Go 编程语言执行的 HTTP 页面。 GO 中的函数如下所示:

func main(){
...
http.HandleFunc("/Page", func(w http.ResponseWriter, r *http.Request) {
t:=template.New("New template")
child_template := t.New("New child template")
_, _ = child_template.Parse(output) // output is from the omitted code
t, err = t.ParseFiles("HTML_template.html")
_ = t.ExecuteTemplate(w, "HTML_template.html", output)
}
}

如何让/Page 自行刷新?我尝试了以下方法,但它不起作用。

func main(){
...
http.HandleFunc("/Page", func(w http.ResponseWriter, r *http.Request) {
for{
t:=template.New("New template")
child_template := t.New("New child template")
_, _ = child_template.Parse(output) // output is from the omitted code
t, err = t.ParseFiles("HTML_template.html")
_ = t.ExecuteTemplate(w, "HTML_template.html", output)

time.Sleep(time.Millisecond*100)
}
}
}

我正在尝试制作一个动态图来绘制每秒传入数据的数量。如果我不断刷新浏览器,轴也会重新加载,看起来很难看。 HTML_template.html 看起来像这样

<script type = "text/javascript">
function plot(){
...
var data = [{{template "New child template"}}];
...
}
setInterval(func(){plot()},500);
</script>

最佳答案

这可以在没有 Go、JavaScript、AJAX、SSE 或 Websockets 的情况下通过简单地添加 refresh 来完成。元标记。添加

<meta http-equiv="refresh" content="3" />

进入您页面的<head>将使其每 3 秒刷新一次。

关于戈朗 : Automatic Refresh of a HTTP Page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24560111/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com