Search code examples
ajaxjquerygrailsgrails-controller

grails remoteLink no working as expected


I am trying to use Ajax asynchronous call backs with grails. In my gsp file head I have:

    <g:javascript library="prototype" />

in the body I have:

        <g:remoteLink controller="dashboard" action="showTime" update="time">Show the Time</g:remoteLink> 

    <div id="time"></div>

on my controller I have:

    def showTime = {
         System.print("time");
         render "The time is ";
}

I would expect that the div "time" in my gsp file would be replaced with the rendered text "The time is". Instead, nothing seems to happen. I know that my controller fires, because of the System.print but nothing is updated in the div.

I noticed that onload of the page, I get this error generated: "element.dispatch is not an event" in the prototype.js page. If I remove

 <g:javascript library="prototype" />

I no longer get that error but the whole page is redirected to dashboard/showTime

What am I doing wrong here?

thanks jason


Solution

  • Are you using both jquery (or some other JS library) and prototype libraries? This problem is usually caused by using BOTH jquery.js and prototype.js. You might not be seeing jquery being loaded (maybe it's in the layout or in the < body >, check the JS libraries loaded using firebug.

    If you are loading both, comment out jquery and just use prototype. Check it again and it should be working, updating the < div >. I hope that helps.