我有一个代码可以启动服务器并停止服务器。但是,当我按下按钮时,服务器会启动,但也会将我重定向到新 View 。我在 Controller 中的代码是
def test= amazonWebService.ec2.startInstances(new StartInstancesRequest([InstanceToStart]))
我想在按下按钮时执行测试,而无需进入新 View 。我在gsp页面中的代码是
<g:link action="test">
<input type="button" value="Start Server" class="button" id="startServer1" />
</g:link>
最佳答案
如果您不介意页面刷新,请在测试操作中将页面重定向到您来自的 View 。因此,假设您通过索引进入了当前 View :
class SomeController {
def index() {
// index.gsp rendered via convention
}
def test() {
// execute your code then
redirect action: index, params: params
}
}
您还可以选择单击链接时提交Ajax请求,而不必完全刷新页面。
关于ajax - 如何在不使用Grails的情况下执行 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16546250/