开发者

Grails remoteLink

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 ja开发者_开发问答vascript 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>


I found out that the problem was not with the Ajax. It was a mistake in the Javascript function. I was calling alert.window() instead of window.alert(). Thanks for the Firebug tip Gregg.


I understand your problem completely,

Please change your code to :

< g:remoteLink controller="event" action="recommend" id="1" onSuccess="recommend(data)" params="[artist:searchedArtist]"> Recommend </g:remoteLink>

you must pass data in onSuccess and onFailure function grails only understand it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜