Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax Grails刷新分区_Ajax_Grails_Html - Fatal编程技术网

Ajax Grails刷新分区

Ajax Grails刷新分区,ajax,grails,html,Ajax,Grails,Html,我的网站上有这样的内容: <body> <div id="1"> content1 </div> <div id="2"> content2 </div> <g:render template="/layouts/aa1"/> <g:form name="myForm" action="myaction"> <g:submitButton name="update" value="Update" /&g

我的网站上有这样的内容:

<body>
<div id="1">
content1
</div>
<div id="2">
content2
</div>

<g:render template="/layouts/aa1"/>

<g:form name="myForm" action="myaction">
<g:submitButton name="update" value="Update" />
</g:form>
</body>
我想做的是,当我单击“更新”时,会再次调用g:render并使用ajax进行更新(仅更新该部分),并且值会更改。每次单击,都会显示接下来的20辆车。我怎样才能做到这一点?我的方向正确吗?

Grails有一个标签可以为您实现这一点。 基本上,不使用常规的
form
标记,而是使用
formRemote
标记,指定要调用的控制器和操作以及要用结果更新的dom元素。 您还可以查看标记,它具有类似的功能

我在下面删掉了一些代码,让你朝着正确的方向前进。它未经测试,因此可能存在错误

控制器:

def updateDiv = {
    def max = 20
    def offset = 0 

    if(params=["myForm"]){
       def print = Cars.list(max: max, offset: offset + 10)
    }

    render(template:'aa1', collection:print, var:'car')
}
普惠制:

def updateDiv = {
def max = 20
def offset = 0 
   if(params=["myForm"]){
       def print = Cars.list(max: max, offset: offset + 10)
   }
render(template:'aa1', [print: print])
}
def updateDiv = {
    def max = 20
    def offset = 0 

    if(params=["myForm"]){
       def print = Cars.list(max: max, offset: offset + 10)
    }

    render(template:'aa1', collection:print, var:'car')
}
<body>
    <div id="1">
        content1
    </div>
    <div id="2">
        content2
    </div>

    <g:formRemote name="myForm" on404="alert('not found!')" update="3"
              url="[ controller: 'YourControllerName', action:'updateDiv' ]">
        Book Id: <input name="id" type="text"></input>
    </g:formRemote>

    <div id="3">
         <g:render id="" template="/layouts/aa1" collection="${print}"/>
    </div>
</body>
${car.carModel}