Pass Javascript Variable into createlink method call Grails

十年热恋 提交于 2019-12-01 02:00:41

问题


var search= document.getElementById('appMenu').value 
document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch',   params: ['query': search])}'

The element appMenu is a text field, so I am getting the value that the user enters into the text box to pass into a search controller. However, it keeps telling me that the params query is null. It seems that search isn't being passed into the create link method. Anyone have a suggestion?


回答1:


Grails (controllers, GSP and tags, etc) are working on server side. JavaScript on client side. And this link is prepared before sending data to browser, and before JavaScript can pass its variable into GSP tag.

But you can prepare base link on server side, and add extra parameter on client side, by using javascript, like:

var search= document.getElementById('appMenu').value;
document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch')}?query=' + escape(search);


来源:https://stackoverflow.com/questions/11037614/pass-javascript-variable-into-createlink-method-call-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!