试图在BS popover中使用ajax formRemote。 一个简单的表单可以工作,但ajax实现不是:
1)gsp代码
<div id="addfolder">
<a href="#" class="btn" id="nrfolder" rel="popover">
<i class="icon-folder-close icon-large"></i></a><%--<g:message code="folder" args="[entityName]" default="New Folder"/>--%></a>
</div>
<div id="newRootFolder" style="display:none;">
<form class="form-inline" style="width:280px;">
<g:formRemote name="createRootFolder" url="[controller:'folders',action:'create']" onLoading="showModalSpinnerNewFolder();" onComplete="hideModalSpinnerNewFolder();" onSuccess="doResponseNewFolder(data);" >
<g:textField name="folderName" class="input-small" type="text" placeholder="New folder"/>
<input type="submit" value="Create" class="btn btn-info" />
<a href="#" class="btn" onclick="$('#nrfolder').popover('hide')"/>Cancel</a>
</g:formRemote>
</g:formRemote>
</form>
</div>
2)用jquery调用popover
$('#nrfolder').popover({placement:'right',title:'New Root Folder',html:true,content: function() { return $('#newRootFolder').html();} });
3)jquery成功事件:doResponseNewFolder函数
function doResponseNewFolder(data) {
alert('toto' + data.success);
if (data.success == 'true') {
var msg = data.msg;
// reload tree view
$('#tree').dynatree('getTree').reload();
} else {
var msg = $('<ul class="errors">');
for (var i = 0; i < data.errorList.length; i++) {
msg.append('<li>' + data.errorList[i] + "</li>");
}
}
$('#new_folder_msg').html(msg);
$('#new_folder_msg').show();
}
有什么想法吗?
答案 0 :(得分:1)
看起来你搞乱了表单,让我解释一下:Grails'g:formRemote
是制作ajax web表单的助手,所以如果你查看生成的HTML,会在调用时生成一个表单
事实是您已经打开了一个表单,该表单不是有效的HTML语法。第一种形式不应该存在。您可以将其属性提供给g:formRemote
,Grails会将其传递给您生成的form
:
<g:formRemote class="form-inline" style="width:280px;" name="createRootFolder" url="[controller:'folders',action:'create']" onLoading="showModalSpinnerNewFolder();" onComplete="hideModalSpinnerNewFolder();" onSuccess="doResponseNewFolder(data);" >
<g:textField name="folderName" class="input-small" type="text" placeholder="New folder"/>
<input type="submit" value="Create" class="btn btn-info" />
<a href="#" class="btn" onclick="$('#nrfolder').popover('hide')"/>Cancel</a>
</g:formRemote>
这一点,没有其他形式的叠加,就足够了。