Go - 如何加载新的 html 表单
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须将原始表单放入标签(例如 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.
在 javascript 中:
在 golang 中,您可以使用
http.Redirect
函数,像这样:In javascript:
In golang, you can use the
http.Redirect
function, like this:请注意:这似乎可以通过以下方式解决:我只需要执行“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.