Go - 如何加载新的 html 表单

发布于 2024-11-07 10:04:31 字数 371 浏览 0 评论 0原文

在 Go 程序中成功处理来自 HTML 表单的 jQuery Ajax Post 后,如何加载新表单?我首先尝试发送表单作为响应,Javascript 显示它,但它没有清除旧的(现有)表单。然后,我尝试在 HTML Javascript 中使用“window.location = 'localhost:8088/MaintForm/'”设置 URL。这会导致浏览器发出警告,但不会加载表单,也不会更改 URL。理想情况下,我想了解这两种方法 - 通过充当服务器的 Go 程序和通过 Javascript。如果我手动更改 URL,表单加载正常。我想做的是接收 Javascript (jQuery Ajax) 的响应,然后如果响应是肯定的则请求新表单。我更愿意在不更改 URL 的情况下执行此操作。正如我上面所说,这部分奏效了。

After processing a jQuery Ajax Post from an HTML form successfully within a Go program, how do I load a new form? I first tried sending the form as the response and the Javascript displayed it, but it did not clear the old (existing) form. I then tried within the HTML Javascript to set the URL using "window.location = 'localhost:8088/MaintForm/'". That resulted in a warning from the browser but did not load the form and did not change the URL. I would like to ideally know both methods - via the Go program acting as a server, and via Javascript. If I manually change the URL, the form loads OK. What I am trying to do is receive a response in Javascript (jQuery Ajax), and then request the new form if the response is positive. I would prefer to do this without changing the URL. As I said above, this partially worked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初熏 2024-11-14 10:04:31

您必须将原始表单放入标签(例如 div)中,并使用 JQuery 代码将该标签的内容替换为新表单。这样您就不会更改 URL。

这更像是一个 javascript/JQuery 问题,而不是特定于 go 的问题。

You would have to put your original form inside a tag, for example a div, and use your JQuery code to replace the contents of that tag with the new form. This way you are not changing the URL.

This is more of a javascript/JQuery question than a go-specific one.

浅唱々樱花落 2024-11-14 10:04:31

在 javascript 中:

location.href = '/MaintForm/';

在 golang 中,您可以使用 http.Redirect函数,像这样:

http.Redirect(w, r, "/MaintForm/", http.StatusFound)

In javascript:

location.href = '/MaintForm/';

In golang, you can use the http.Redirect function, like this:

http.Redirect(w, r, "/MaintForm/", http.StatusFound)
听风念你 2024-11-14 10:04:31

请注意:这似乎可以通过以下方式解决:我只需要执行“document.write(data);”在 JavaScript 中。 “数据”包含新的 HTML。

Please note: this appears to be solved by : I just need to do an "document.write(data);" in Javascript. "Data" contains the new HTML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文