在Grails中调用Ajax

时间:2015-01-22 07:10:46

标签: ajax grails

我是Grails的新手,面临以下问题。我有一个显示表单的弹出窗口。我想进行Ajax调用以保存(def保存)表单详细信息并保持相同的弹出窗口。但Grails控制器总是呈现save.gsp。我相信Ajax调用会阻止页面的呈现,但它仍然在发生。我也尝试过使用formRemote标签。 save.gsp仍在渲染中。我想在updateMe占位符的弹出窗口中查看save.gsp的内容。而是整个页面被渲染。什么是最好的解决方案?

我的代码如果在下面给出:(它真的很粗糙,所以请原谅我!)

configuration.gsp

<g:formRemote name="myForm" on404="alert('not found!')" update="updateMe"
              url="[controller: 'configure', action:'save']">

    <div class="form-group">
        <label>Company Name</label>

        <g:textField name="CompanyName" class="form-control" value="${basicInstance?.CompanyName}" />
    </div>

    <div class="form-group">
        <label>Database</label>

        <g:textField name="DB" class="form-control" value="${basicInstance?.DB}" />
    </div>

    <div class="form-group">
        <label>Username to Data base</label>

        <g:textField name="DBUserName" class="form-control" value="${basicInstance?.DBUserName}" />
    </div>

    <div class="form-group">
        <label>Password to Data base</label>
        <g:textField name="DBPassword" class="form-control" value="${basicInstance?.DBPassword}" />
    </div>

    <div class="form-group">
        <label>URL to Data base</label>

        <g:textField name="URL" class="form-control" value="${basicInstance?.URL}" />
    </div>

    <g:link>
        <div class="buttons">
            <span class="button"  ><g:submitButton name="save" class="btn btn-primary" value="SUBMIT"  /></span>
        </div>
    </g:link>

    <div id="updateMe"></div>
</g:formRemote>

configureController

package mdm

import groovy.sql.Sql

class ConfigureController {

    static allowedMethods = [save: "POST"]

    def configuration={
        def basicInstance = new BasicDBInfo()

        basicInstance.properties=params

        return [basicInstance: basicInstance]
    }

    def save={

        def basicInstance = new BasicDBInfo(params)

        if (basicInstance.save(flush: true)) {

            flash.message = "${message(code: 'default.created.message', args: [message(code: 'BasicDBInfo.label', default: 'BasicDBInfo'), basicInstance.id])}"

            render(view: "save")
        }
        else {
            flash.message = "${message( args: [message(code: 'administrator.label', default: 'soemthing is wrong'), basicInstance.id])}"
        }
    }
}

0 个答案:

没有答案