我的GSP上有此按钮
<button id = "select"
onclick = "${remoteFunction(controller: 'customer', action: 'selectBatch',
params: '\'batchID=\' + selectedBatchID')}">Select</button>
我在同一按钮上也有此javascript函数:
$('#select').click(function () {
if (selectedBatchID == undefined) {
$("#errorMessages p").text("Click a row to choose a batch first.");
$("#errorMessages p").show();
$("#errorMessages p").fadeOut(3000);
}
else {
$("#choosebatch h2").text("Batch ID " + selectedBatchID + ": " + selectedBatchDesc);
}
我想做的是将GSP代码中声明的按钮的onclick函数移动到javascript函数的else子句中,以便 Controller 功能不会一直启动,仅当执行javascript else子句时。我只是似乎找不到正确的语法。任何帮助/提示表示赞赏。
最佳答案
与先前的答案类似的是,您可以尝试以下操作:
$.ajax({
type: 'POST',
url: "${createLink(action:'customer', controller:'selectBatch')}/batchID=" + selectedBatchID
});