我需要进行 Ajax 查询来调用 Service 对象中的一个方法,该方法接受 3 个参数并返回一个布尔值。然后,我将这个布尔值用于在发布前发生的验证消息。
这就是我目前所拥有的(不工作),但我尝试了其他事情但无济于事。我们正在使用 JQuery 和 Grails:
var isUnique = ${remoteFunction(
service: 'Project',
action:'checkUniqueUserProjectId',
params:{
// These values are from hidden fields in the form.
// userId and projectId are string values and the group is an object
uniqueId: userId,
group: userGroup,
projectId: myProjectId
}
)}
这是在 ProjectService 中调用的方法:
// Check whether or not a Project with the provided uniqueId already exists
// in the database that is not itself.
def checkUniqueUserProjectId(uniqueId,group,projectId) {
def filterCriteria = Project.createCriteria()
def projectList = filterCriteria.list {
and {
eq("userProjectId", uniqueId)
eq("group", group)
ne("id",projectId)
}
}
if(projectList.empty)
return true
else
return false
}
任何帮助将不胜感激!