pass javascript variables into grails params -


so need pass javascript variables grails parameters build , download file. did ajax learn ajax doesn't downloads. worked so:

<script type="text/javascript" charset="utf-8">     function myfunction() {          jquery.ajax({             url: "search/download",             type: "post",             data: {facets: visualsearch.searchquery.facets()}         });     } </script> <input type="button" onclick="myfunction()" value="download"> 

while passed mapping correctly, didn't downloads.

so want similar g:link

<g:link controller="search" action="test" params="[facets: '\$(visualsearch.searchquery.facets())']" >test grails</g:link> 

but in params in controller are

facets=$(visualsearch.searchquery.facets()) action=test controller=search 

how can fix pass facets (whether parsed or unparsed) controller. thanks!

adding javascript variable in params not work. g:link executed on server side , has no knowledge of javascript values. can remove params , instead add code on `onclick' event of link set javascript values in params.

something like: in gsp page,

<g:link name="searchlink" controller="search" action="test">test grails</g:link> 

and in javascript (in same page),

$(function() {   $('a[name="searchlink"]').bind('click', function() {     $(this).attr('href', $(this).attr('href') + '?facets=' + visualsearch.searchquery.facets());   }) }) 

basically using grails generate hyperlink , using jquery append query string parameters href

hope helps.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -