0
$('#andiebox').append('<g:link controller="search" action="search" params="[where:'+destination+', what:what, sort:sort, type:type, distance:distance]">Psychos in HH</g:link>');

this is not accepted by grails, how can i insert the variable correctly?

the variable is clientside generared from a input:

var destination = $(this).attr("id");

            var metaSection = $("#metaSection").val(); 
2
  • 1
    is destination server-side on client-side variable? Commented Mar 18, 2013 at 14:44
  • 1
    Then how do you expect to parse it server side? Commented Mar 18, 2013 at 14:52

1 Answer 1

4

<g:link is server-side tag, so it could only prepare base to your link. All client side parameters should be filled on client side. Something like:

var params = { 
   what: '${what.encodeAsJavaScript()}', //as I understand all this variables are server side variables
   sort: '${sort.encodeAsJavaScript()}', 
   type: '${type.encodeAsJavaScript()}', 
   distance: '${distance.encodeAsJavaScript()}' 
}; 
params.destination =  $(this).attr("id");
var urlBase = '${createLink(controller:"search", action: "search").encodeAsJavaScript()}';

$('#andiebox').append('<a href="' + url + '?' + $.serialize(params) + '">Psychos in HH</a>');
Sign up to request clarification or add additional context in comments.

2 Comments

To be safe you should use var urlBase = '${createLink(...).encodeAsJavaScript()}';, and similarly for the params values (what:'${what.encodeAsJavaScript()}', ...) in case any of them contain characters that need special handling in JavaScript string literals.
Uncaught TypeError: Object function (e,t){return new v.fn.init(e,t,n)} has no method 'params'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.