【发布时间】:2012-06-08 19:27:08
【问题描述】:
我对 Grails 还很陌生,所以请多多包涵。
我的视图有这样的javascript代码:
//js code in my View
function validateEmailAndSetEmail(){
var result =${remoteFunction(controller:'myController',action:'validateEmail',update:'responseDiv', params:'\'email=\'+document.getElementById(\'email\').value')};
if (result) { //doSomething}
}
我的控制器看起来像:
def validateEmail = {
def emailToValidate = request.getParameter("email")
def matchingEmailFound = myService.checkEmailAddress(emailToValidate)
if (matchingEmailFound){
render "This email is already in use.<br>If you have already created an account with this email, please try to reset the password from Login page."}
else{
//setEmail to send here
render "This email is not in use. This email will be used as your account email"}
return !matchingEmailFound
我的问题分为两部分:
当我在 firebug 的 js 代码中检查 result 的值时,它是 不是布尔类型(真/假)并且该值似乎不正确,是否有任何方法可以传递此值 正确地从控制器视图中的 js?
我可以调用 set email value 到某个变量 在我看来,控制器并在 js 之外调用它?
提前致谢。
【问题讨论】:
标签: javascript ajax grails view controller