I'm trying to make a call to the server with Ajax using Grails remoteLink. The code is the following:
<g:remoteLink controller="event" action="recommend" id="1" onSuccess="recommend(e)" params="[artist:searchedArtist]">
Recommend
</g:remoteLink>
The controller is:
def recommend = {
.
.
.
def jsonList = [artist: "${params.artist}",
location: [
lat:"53.872715",
lng:"-1.372895"]
]
render jsonList as JSON
}
and the javascript function is:
function recommend(response){
var recommendedResults = eval('(' + response.responseText + ')');
var point = new google.maps.LatLng(${recommendedResults.location.lat}, ${recommendedResults.location.lng});
var myMarkerOptions = {
position: point,
map: map
};
var marker = new google.maps.Marker(myMarkerOptions);
}
My problem is that the recommend() javascript function is never being called. Any thoughts? Thanks very much.
UPDATE
I just noticed that the line:
var point = new google.maps.LatLng(${recommendedResults.location.lat}, ${recommendedResults.location.lng});
was not right. So just for debugging purposes, I tried with the "recommend()" javascript function like this:
function recommend(response){
alert.window("Foo");
}
and still doesn't work. The alert never pops up.
The code fragment of the remoteLink which appears in the html source is:
<a href="/Ontourtest/event/recommend/1?artist=deftones" onclick="new Ajax.Request('/Ontourtest/event/recommend/1',{asynchronous:true,evalScripts:true,onSuccess:function(e){recommend(e)},parameters:'artist=deftones'});return false;">Recommend</a>